[REBOL] Re: A question about a regular expression
From: gabriele:colellachiara at: 17-Oct-2004 13:58
Hi Lethalman,
On Sunday, October 17, 2004, 1:10:12 PM, you wrote:
>>You only need "*" or something else too?
>>
L> ? is good too... :)
Ok.
L> PS: se vuoi parla anche italiano
In inglese ci capiscono anche gli altri. ;-)
One way is to use FIND/ANY that supports wildcards. However, like
most RE engines do, it can match too much:
>> find/any/tail "<a href='http://bla'>Test</a><a href='http://blabla'>Test2</a>" "<a
href='*'>"
== "Test2</a>"
Another way is to convert the strings to PARSE rules, and then use
them.
>> wildcards: "*?"
>> text: complement charset wildcards
>> result: []
>> wild-rule: [some [copy str any text (append result str) ["*" (append result 'thru)
| "?" (append result 'skip)]]]
>> parse/all "<a href='*'>" wild-rule
>> result
== ["<a href='" thru "'>"]
Note that this won't work if your string has something like "*?"
or "**" in it (it will work for "?*"). You can enhance it to
support that if you think you need it.
Now you can:
>> parse/all "<a href='http://bla'>Test</a><a href='http://blabla'>Test2</a>" [result
mark:]
== false
>> mark
== "Test</a><a href='http://blabla'>Test2</a>"
I think this should be enough to give you a start. :)
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/