Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[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, "my doggyoggy" 11112222 "has as as as as " 111222333444555 "fleasssssss" 1234567 Note that some cases can be solved in multiple ways: "fleassssss" 111222 "fleassssss" 112233 "fleassssss" 123456 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 /(.+)\1+$/ 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? -jn- -- Polonius: ... What do you read, my lord? Hamlet: Words, words, words. _Hamlet_, Act II, Scene 2