[REBOL] Re: Parse versus Regular Expressions
From: joel:neely:fedex at: 5-Apr-2003 9:00
Hi, again, Gabriele,
I've just tripped over a tidy example of a task that's trivial to
solve if backtracking is available.
Find a repeated group of characters at the end of a string (one or more
characters, repeated two or more times consecutively). For example,
"has as as as as "
Note that some cases can be solved in multiple ways:
in which case any solution is OK.
The Perl/Python/etc-style regular expression which tests for this
situation and provides the first occurrence of the repeated group
of characters is
which, for those not familar with RE "line noise" ;-) can be read
(.+) a group (the parens) of one or more (the plus)
arbitrary characters (the dot)
\1 ... followed by the same group previously matched
+ ... one or more times
$ ... at the end of the string
I'm really interested in how a PARSE expert would approach the same
task. Any takers?
Polonius: ... What do you read, my lord?
Hamlet: Words, words, words.
_Hamlet_, Act II, Scene 2