#17 non-Perl compatible behavior with nested quantifiers

open
nobody
None
7
2006-12-13
2006-01-31
No

This:

# php
<?php
$foo = "a \n";
if ( preg_match ( '/\w++\b \n/', $foo ) ) {
print "matched!\n";
} else {
print "didn't match!\n";
}
?>

... and this:

echo 'a ' | grep-cvs -P '\w++\b \n'

behave differently than this:

echo 'a ' | perl -e '$_ = <>; print if m/\w++\b \n/'

The Perl thing to do here is throw an error. Is there a
philosophy or policy set forth for PCRE that it matches
on what would be an invalid Perl regex? An error code
should preferably be sent to the caller, and then
handled by the caller.

If for some reason (like backwards compatibility) it is
unacceptable to return an error code for invalid
regexes, then matching on them still does not seem
appropriate. If a regex is wholly and completely
invalid, no matches should be returned for it.

Discussion

  • Christopher E. Stith

    • priority: 5 --> 7
     
  • Nobody/Anonymous

    Logged In: NO

    ++ is a "possessive quantifier", as documented in the pcrepattern man page. First invented in Java, I think, then added to PCRE. It will no longer be incompatible with Perl when Perl 5.10 comes out. (Comment added by PH)

     

Log in to post a comment.