On Fri, Nov 07, 2003 at 03:51:02PM -0000, Mihail Egorov wrote: > > #!/usr/bin/perl -w > > print 1 if "ApqZ" =~ /A ( (?> [^p]* ) | (?> p[^pZ]* ) ) Z/x; > print 2 if "ApqZ" =~ /A (?> (?> [^p]* ) | (?> p[^pZ]* ) ) Z/x; > print 3 if "ApqZ" =~ /A (?> (?> p[^pZ]* ) ) Z/x; > > print "\n This program has to print '123', and really prints only '13'." ; > print "\n This is considered to be a 'nested regex without backtracking' bug." ; > print "\n"; This behaviour is correct. After the "A", the regexp engine tries to match as many non-p's as possible and succeeds, matching zero of them. The surrounding (?> ) means that the first thing matched is the only thing that can be matched at that position. Since the "Z" doesn't follow the "A" the whole pattern fails. Once a pattern in (?>pattern) is successful there are no second chances. So if (?>A|B) can match A then it will never try to match B no matter what the rest of the pattern is. -- Rick Delaney rick@bort.caThread Previous