[REBOL] 5 simple pattern matching questions Re:
From: al:bri:xtra at: 15-Sep-2000 20:00
> I am having problems switching my understanding of regular expressions to
the REBOL parse dialect. Could someone please tell me how to do each of the
following with parse?
> 1. match "cat" at the beginning of a line
>> line: "cat mat"
== "cat mat"
>> parse line ["cat" to end]
== true
>> line: "mercata"
== "mercata"
>> parse line ["cat" to end]
== false
>> line: "cat"
== "cat"
>> parse line ["cat" to end]
== true
> 2. match "cat", immediately preceded and followed by a word boundary ,
e.g., match "the cat in" or "the cat" but not "mercata"
>> line: "mercata"
== "mercata"
>> parse line [thru " cat " to end]
== false
>> line: "the cat in"
== "the cat in"
>> parse line [thru " cat " to end]
== true
> 3. match "cat" on a line all by itself
>> line: "cat"
== "cat"
>> parse line ["cat"]
== true
>> line: "cat "
== "cat "
>> parse line ["cat"]
== false
> 4. match the empty string: I think this is
> parse string ""
>> Line: ""
== ""
>> empty? line
== true
> 5. match any char: I think this is done by creating a bitset from a
charset from hex 000 to hex 255 and parsing on that, but it doesnt work,
e.g.,
> bset: charset [ #"^(00)" - #"^(FF)" ]
> parse " " [ some bset ]
>
> fails
Any one?
Andrew Martin
4/5 can't be tooooo bad...
ICQ: 26227169
http://members.ncbi.com/AndrewMartin/
http://members.xoom.com/AndrewMartin/