This solution doesn't use regular expressions or parsing. But it's far
easier to see what the intent of the code is. Parsing is my second
solution...
I did it this way, because the (^) caret[?sp] in REBOL strings is the
escape character for encoding special characters in strings. Note that the
"^" disappears from bobr's original code:
>> userlist: {^(ted|admin|bobr|andrew|elan|keith|cheryl|joel|brady)$}
== {(ted|admin|bobr|andrew|elan|keith|cheryl|joel|brady)$}
>> userlist
== {(ted|admin|bobr|andrew|elan|keith|cheryl|joel|brady)$}
>> User_List: ["ted" "admin" "bobr" "andrew" "elan" "keith" "cheryl" "joel"
"brady"]
== ["ted" "admin" "bobr" "andrew" "elan" "keith" "cheryl" "joel" "brady"]
>> Current_User: "bobr"
== "bobr"
>> found? find User_List Current_User
== true
>> Current_User: "Intruder"
== "Intruder"
>> found? find User_List "Intruder"
== false
>> New_User: "Wolfgang Amadeus Mozart"
== "Wolfgang Amadeus Mozart"
>> append User_List New_User
== ["ted" "admin" "bobr" "andrew" "elan" "keith" "cheryl" "joel" "brady"
"Wolfgang Amadeus Mozart"]
>> found? find User_List "Wolfgang Amadeus Mozart"
== true
A similar procedure will work for file names as well.
>> Files: [%notxt. %ask_new. %only_owner_may_edit.]
== [%notxt. %ask_new. %only_owner_may_edit.]
>> type? second Files
== file!
>> found? find Files %My_Favourite_Martian.html
== false
>> found? find Files %ask_new.
== true
>> source is-memberof-re
is-memberof-re: func [Series [series!] Value [any-type!]][found? find Series
Value]
>> is-memberof-re Files %ask_new.
== true
>> is-memberof-re Files %My_favourite_Martian.html
== false
If you want, you can use parse like this:
>> User_List: ["ted" | "admin" | "bobr" | "andrew" | "elan" | "keith" |
"cheryl" | "joel" | "brady"]
== ["ted" | "admin" | "bobr" | "andrew" | "elan" | "keith" | "cheryl" |
"joel" | "brady"]
>> parse "bobr" User_list
== true
>> parse "Intruder" User_list
== false
Or for another approach, using 'parse:
>> userlist: ask "Please enter users: "
Please enter users: ^(ted|admin|bobr|andrew|elan|keith|cheryl|joel|brady)$
== {^^(ted|admin|bobr|andrew|elan|keith|cheryl|joel|brady)$}
Users: make object! [
Names: make block! 10
Name: make string! 30
Name_Rule: [
copy Name [to "|" | to ")"] (append Names Name) [thru "|" | thru ")"]
]
Parse_Names: func [Simple_RegExp [string!]] [
clear Names clear Name
parse/all Simple_RegExp ["^^(" some Name_Rule thru "$" to end]
]
]
print Users/Parse_Names userlist
print mold Users/Names
>> do %"Simple RegExp.r"
Script: "Simple RegExp" (20-Jan-1999)
Please enter users: ^(ted|admin|bobr|andrew|elan|keith|cheryl|joel|brady)$
true
["ted" "admin" "bobr" "andrew" "elan" "keith" "cheryl" "joel" "brady"]
Then implement as above.
I'm sure that Gabrielle and Elan could write more concise parse rules, but
it does the job.
Andrew Martin
ICQ: 26227169
[EMAIL PROTECTED]
http://members.xoom.com/AndrewMartin/
-><-