Perl Compatible Regular Expressions - Differences From Perl

Differences From Perl

PCRE's specification has the following differences to Perl's regular expression (as of Perl 5.9.4):

Recursive matches are atomic in PCRE and non atomic in Perl
This means that "<!>!>><>>!>!>!>" =~ /^(<(?:+|(?3)|(?1))*>)(!>!>!>)$/ will match in Perl but not in PCRE.
The value of a capture buffer deriving from the ? quantifier (match 1 or 0 times) when nested in another quantified capture buffer is different
"aba" =~ /^(a(b)?)+$/; will result in $1 containing 'a' and $2 containing undef in Perl, but in PCRE will result in $2 containing 'b'.
PCRE allows named capture buffers to be given numeric names; Perl requires the name to follow the rule of barewords
This means that \g{} is unambiguous in Perl, but potentially ambiguous in PCRE.
PCRE does not support certain "experimental" Perl constructs
such as (??{...}) (a callback whose return is evaluated as being part of the pattern) nor the (?{}) construct, although the latter can be emulated using (?Cn). Recursion control verbs added in the Perl 5.9.x series are also not supported. Support for experimental backtracking control verbs (added in Perl 5.10) is available in PCRE since version 7.3. They are (*FAIL), (*F), (*PRUNE), (*SKIP), (*THEN), (*COMMIT), and (*ACCEPT). Perl's corresponding use of arguments with backtracking control verbs is not generally supported. Note however that since version 8.10, PCRE supports the following verbs with a specified argument: (*MARK:markName), (*SKIP:markName), (*PRUNE:markName), and (*THEN:markName).
PCRE and Perl are slightly different in their tolerance of erroneous constructs
Perl allows quantifiers on the (?!) construct, which is meaningless but harmless (albeit inefficient); PCRE produces an error. (Note that such assertions can be harmlessly quantified with PCRE beginning with version 8.13, so the cited example applies only to earlier versions.)
PCRE has a hard limit on recursion depth, Perl does not
With default build options "bbbbXcXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" =~ /.X(.+)+X/ will fail to match due to stack overflow, but Perl will match this correctly. Perl uses the heap for recursion and has no hard limit for recursion depth, whereas PCRE has a compile time hard limit.

With the exception of the above points PCRE is capable of passing the tests in the Perl 't/op/re_tests' file, one of the main syntax level regression tests for Perl's regular expression engine.

Read more about this topic:  Perl Compatible Regular Expressions

Famous quotes containing the word differences:

    The differences between revolution in art and revolution in politics are enormous.... Revolution in art lies not in the will to destroy but in the revelation of what has already been destroyed. Art kills only the dead.
    Harold Rosenberg (1906–1978)