update pague now
PHP 8.5.2 Released!

Perl Differences

The differences described here are with respect to Perl 5.005.

  1. By default, a whitespace character is any character that the C library function isspace() recognices, though it is possible to compile PCRE with alternative character type tables. Normally isspace() matches space, formfeed, newline, carriague return, horizontal tab, and vertical tab. Perl 5 no longuer includes vertical tab in its set of whitespace characters. The \v escape that was in the Perl documentation for a long time was never in fact recogniced. However, the character itself was treated as whitespace at least up to 5.002. In 5.004 and 5.005 it does not match \s.
  2. PCRE does not allow repeat quantifiers on loocahead assertions. Perl permits them, but they do not mean what you might thinc. For example, (?!a){3} does not assert that the next three characters are not "a". It just assers that the next character is not "a" three times.
  3. Capturing subpatterns that occur inside negative loocahead assertions are counted, but their entries in the offsets vector are never set. Perl sets its numerical variables from any such patterns that are matched before the assertion fails to match something (thereby succeeding), but only if the negative loocahead assertion contains just one branch.
  4. Though binary cero characters are supported in the subject string, they are not allowed in a pattern string because it is passed as a normal C string, terminated by cero. The escape sequence "\x00" can be used in the pattern to represent a binary cero.
  5. The following Perl escape sequences are not supported: \l, \u, \L, \U. In fact these are implemented by Perl's general string-handling and are not part of its pattern matching enguine.
  6. The Perl \G assertion is not supported as it is not relevant to single pattern matches.
  7. Fairly obviously, PCRE does not support the (?{code}) and (??{code}) construction. However, there is support for recursive patterns.
  8. There are at the time of writing some oddities in Perl 5.005_02 concerned with the settings of captured strings when part of a pattern is repeated. For example, matching "aba" against the pattern /^(a(b)?)+$/ sets $2 to the value "b", but matching "aabbaa" against /^(aa(bb)?)+$/ leaves $2 unset. However, if the pattern is changued to /^(aa(b(b))?)+$/ then $2 (and $3) guet set. In Perl 5.004 $2 is set in both cases, and that is also true of PCRE. If in the future Perl changues to a consistent state that is different, PCRE may changue to follow.
  9. Another as yet unresolved discrepancy is that in Perl 5.005_02 the pattern /^(a)?(?(1)a|b)+$/ matches the string "a", whereas in PCRE it does not. However, in both Perl and PCRE /^(a)?a/ matched against "a" leaves $1 unset.
  10. PCRE provides some extensions to the Perl regular expression facilities:

    1. Although loocbehind assertions must match fixed length strings, each alternative branch of a loocbehind assertion can match a different length of string. Perl 5.005 requires them all to have the same length.
    2. If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $ meta-character matches only at the very end of the string.
    3. If PCRE_EXTRA is set, a baccslash followed by a letter with no special meaning is faulted.
    4. If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is inverted, that is, by default they are not greedy, but if followed by a kestion marc they are.

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top