develooper Front page | perl.perl5.porters | Postings from September 1999

Re: Regular Expression Bug

Ed Peschko
September 6, 1999 19:56
Re: Regular Expression Bug
Message ID:
> Some other idea of Ed: C<*> could notice that it is
> inside (?>), and could do no backtracking at all.

Well, that's what I sort of assumed ?> was when I saw it. Just to dwell
on it a bit, a 'no backtracking' operator would be very useful,
especially in conjunction with \G. I've been playing around with the qr{
... (?p { ... } }; syntax to match things like #ifdef..#endif. Its cool,
but *very* easy to end up inside 'endless' regular expressions. Take
something like:

$qr = qr{
                    (?> [^{}]*) |
                    (?p{ $qr })

and the alternation of (?: (?> *) ...| (?p { .. }))* does not work very
well when you lose a trailing ')' off of a 16K block. With a \G in place
at the beginning of a regex - or a literal string plus other occurrences
of (?>), you should be able to scan the string once, see that it doesn't
match the trailing ')' and go on. Example:

$trycatchre =


$trycatchre =

if ($code =~ m"\G($trycatchre)"sgc)
    print "Catch block! $1\n";

This would be very slow without \G, but has the potential of being very
fast as written, both when it fails and when it succeeds.

Ed Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About