At 08:25 AM 6/7/2001 -0700, Martin Weinless wrote:
>take the regexp '.n+..?.?v*.'
>
>By all that is sacred, if we use the string 'supernova', there should be
>no match since there are too many characters before the 'n'
>
>However, any regexp checking code will report a match.

Atom by atom:

. -  match a character.  Will match the 's' to begin with.
n+ - match 'n' one or more times.  Since the second character isn't a 'n'' 
it has to advance the pointer until the . matches the 'r'.
. - match a character.   Matches 'o'.
.? - match a character 0 or 1 times.  Will match 'v' to begin with (greedy).
.? - match a character 0 or 1 times.  Will match 'a' to begin with.
v* - match 'v' 0 or more times. We're at the end of the string initially, 
so we match none.
. - match a characer.  Oops, there aren't any.  Never mind, we have some 
backtracking we can try.  First one is to take that last .? and match 0 
instead of 1 character.  Now the v* matches 0 characters and the final . 
matches the 'a'.  Success!

Reply via email to