japhy has asked for the wisdom of the Perl Monks concerning the following question:
Now, before you ask, this is related to a) unrolling the loop, and b) reversing a regex. But it's also a very isolated case of the regex engine being a ninny.m{ A # A (?: [^AB]* # 0 or more non-A and non-B characters . B # any character, then a B )* # this combo, 0 or more times [^AB]* # 0 or more non-A and non-B characters A # an A }x
At this point, Perl should NOT try to do:BEFORE & AFTER REGEX <> <A01234567890A> A <A> <01234567890A> [^AB]* <A01234567890> <A> . <A01234567890A> <> B FAILED <A0123456789> <0A> . <A01234567890> <A> B FAILED
since Perl should KNOW that '0' was matched by [^AB]*, so it can't POSSIBLY match B. Instead, Perl should realize it should give up, and continue:<A012345678> <90A> . <A0123456789> <0A> B FAILED
This is NOT the case. Perl zips ALL the way back to the first 0 in the string, trying to match .B until it is exhausted, and goes back to the '...890' having been matched by [^AB]*, and it goes to the [^AB]* outside the (?:...)*. This matches nothing, and then the 'A' matches.<A01234567890> <A> [^AB]* <A01234567890> <A> A <A01234567890A> <> FINISHED
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl's regex engine causes me distress
by japhy (Canon) on Sep 21, 2000 at 23:21 UTC | |
|
Re (tilly) 1: Perl's regex engine causes me distress
by tilly (Archbishop) on Sep 21, 2000 at 23:14 UTC | |
|
Re: Perl's regex engine causes me distress
by japhy (Canon) on Sep 23, 2000 at 07:12 UTC | |
|
Re: Perl's regex engine causes me distress
by demerphq (Chancellor) on Jan 08, 2007 at 21:45 UTC | |
by sgt (Deacon) on Feb 07, 2007 at 10:44 UTC |