Annotation of embedaddon/pcre/doc/html/pcrecompat.html, revision 1.1.1.4

1.1       misho       1: <html>
                      2: <head>
                      3: <title>pcrecompat specification</title>
                      4: </head>
                      5: <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
                      6: <h1>pcrecompat man page</h1>
                      7: <p>
                      8: Return to the <a href="index.html">PCRE index page</a>.
                      9: </p>
                     10: <p>
                     11: This page is part of the PCRE HTML documentation. It was generated automatically
                     12: from the original man page. If there is any nonsense in it, please consult the
                     13: man page, in case the conversion went wrong.
                     14: <br>
                     15: <br><b>
                     16: DIFFERENCES BETWEEN PCRE AND PERL
                     17: </b><br>
                     18: <P>
                     19: This document describes the differences in the ways that PCRE and Perl handle
                     20: regular expressions. The differences described here are with respect to Perl
                     21: versions 5.10 and above.
                     22: </P>
                     23: <P>
1.1.1.2   misho      24: 1. PCRE has only a subset of Perl's Unicode support. Details of what it does
                     25: have are given in the
1.1       misho      26: <a href="pcreunicode.html"><b>pcreunicode</b></a>
                     27: page.
                     28: </P>
                     29: <P>
                     30: 2. PCRE allows repeat quantifiers only on parenthesized assertions, but they do
                     31: not mean what you might think. For example, (?!a){3} does not assert that the
                     32: next three characters are not "a". It just asserts that the next character is
                     33: not "a" three times (in principle: PCRE optimizes this to run the assertion
                     34: just once). Perl allows repeat quantifiers on other assertions such as \b, but
                     35: these do not seem to have any use.
                     36: </P>
                     37: <P>
                     38: 3. Capturing subpatterns that occur inside negative lookahead assertions are
1.1.1.4 ! misho      39: counted, but their entries in the offsets vector are never set. Perl sometimes
        !            40: (but not always) sets its numerical variables from inside negative assertions.
1.1       misho      41: </P>
                     42: <P>
                     43: 4. Though binary zero characters are supported in the subject string, they are
                     44: not allowed in a pattern string because it is passed as a normal C string,
                     45: terminated by zero. The escape sequence \0 can be used in the pattern to
                     46: represent a binary zero.
                     47: </P>
                     48: <P>
                     49: 5. The following Perl escape sequences are not supported: \l, \u, \L,
                     50: \U, and \N when followed by a character name or Unicode value. (\N on its
                     51: own, matching a non-newline character, is supported.) In fact these are
                     52: implemented by Perl's general string-handling and are not part of its pattern
                     53: matching engine. If any of these are encountered by PCRE, an error is
                     54: generated by default. However, if the PCRE_JAVASCRIPT_COMPAT option is set,
                     55: \U and \u are interpreted as JavaScript interprets them.
                     56: </P>
                     57: <P>
                     58: 6. The Perl escape sequences \p, \P, and \X are supported only if PCRE is
                     59: built with Unicode character property support. The properties that can be
                     60: tested with \p and \P are limited to the general category properties such as
                     61: Lu and Nd, script names such as Greek or Han, and the derived properties Any
                     62: and L&. PCRE does support the Cs (surrogate) property, which Perl does not; the
                     63: Perl documentation says "Because Perl hides the need for the user to understand
                     64: the internal representation of Unicode characters, there is no need to
                     65: implement the somewhat messy concept of surrogates."
                     66: </P>
                     67: <P>
1.1.1.4 ! misho      68: 7. PCRE does support the \Q...\E escape for quoting substrings. Characters in
1.1       misho      69: between are treated as literals. This is slightly different from Perl in that $
                     70: and @ are also handled as literals inside the quotes. In Perl, they cause
                     71: variable interpolation (but of course PCRE does not have variables). Note the
                     72: following examples:
                     73: <pre>
                     74:     Pattern            PCRE matches      Perl matches
                     75: 
                     76:     \Qabc$xyz\E        abc$xyz           abc followed by the contents of $xyz
                     77:     \Qabc\$xyz\E       abc\$xyz          abc\$xyz
                     78:     \Qabc\E\$\Qxyz\E   abc$xyz           abc$xyz
                     79: </pre>
                     80: The \Q...\E sequence is recognized both inside and outside character classes.
                     81: </P>
                     82: <P>
1.1.1.4 ! misho      83: 8. Fairly obviously, PCRE does not support the (?{code}) and (??{code})
1.1       misho      84: constructions. However, there is support for recursive patterns. This is not
                     85: available in Perl 5.8, but it is in Perl 5.10. Also, the PCRE "callout"
                     86: feature allows an external function to be called during pattern matching. See
                     87: the
                     88: <a href="pcrecallout.html"><b>pcrecallout</b></a>
                     89: documentation for details.
                     90: </P>
                     91: <P>
1.1.1.4 ! misho      92: 9. Subpatterns that are called as subroutines (whether or not recursively) are
1.1       misho      93: always treated as atomic groups in PCRE. This is like Python, but unlike Perl.
                     94: Captured values that are set outside a subroutine call can be reference from
                     95: inside in PCRE, but not in Perl. There is a discussion that explains these
                     96: differences in more detail in the
                     97: <a href="pcrepattern.html#recursiondifference">section on recursion differences from Perl</a>
                     98: in the
                     99: <a href="pcrepattern.html"><b>pcrepattern</b></a>
                    100: page.
                    101: </P>
                    102: <P>
1.1.1.4 ! misho     103: 10. If any of the backtracking control verbs are used in a subpattern that is
        !           104: called as a subroutine (whether or not recursively), their effect is confined
        !           105: to that subpattern; it does not extend to the surrounding pattern. This is not
        !           106: always the case in Perl. In particular, if (*THEN) is present in a group that
        !           107: is called as a subroutine, its action is limited to that group, even if the
        !           108: group does not contain any | characters. Note that such subpatterns are
        !           109: processed as anchored at the point where they are tested.
        !           110: </P>
        !           111: <P>
        !           112: 11. If a pattern contains more than one backtracking control verb, the first
        !           113: one that is backtracked onto acts. For example, in the pattern
        !           114: A(*COMMIT)B(*PRUNE)C a failure in B triggers (*COMMIT), but a failure in C
        !           115: triggers (*PRUNE). Perl's behaviour is more complex; in many cases it is the
        !           116: same as PCRE, but there are examples where it differs.
1.1       misho     117: </P>
                    118: <P>
1.1.1.4 ! misho     119: 12. Most backtracking verbs in assertions have their normal actions. They are
        !           120: not confined to the assertion.
        !           121: </P>
        !           122: <P>
        !           123: 13. There are some differences that are concerned with the settings of captured
1.1       misho     124: strings when part of a pattern is repeated. For example, matching "aba" against
                    125: the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE it is set to "b".
                    126: </P>
                    127: <P>
1.1.1.4 ! misho     128: 14. PCRE's handling of duplicate subpattern numbers and duplicate subpattern
1.1       misho     129: names is not as general as Perl's. This is a consequence of the fact the PCRE
                    130: works internally just with numbers, using an external table to translate
                    131: between numbers and names. In particular, a pattern such as (?|(?&#60;a&#62;A)|(?&#60;b)B),
                    132: where the two capturing parentheses have the same number but different names,
                    133: is not supported, and causes an error at compile time. If it were allowed, it
                    134: would not be possible to distinguish which parentheses matched, because both
                    135: names map to capturing subpattern number 1. To avoid this confusing situation,
                    136: an error is given at compile time.
                    137: </P>
                    138: <P>
1.1.1.4 ! misho     139: 15. Perl recognizes comments in some places that PCRE does not, for example,
1.1       misho     140: between the ( and ? at the start of a subpattern. If the /x modifier is set,
1.1.1.3   misho     141: Perl allows white space between ( and ? but PCRE never does, even if the
1.1       misho     142: PCRE_EXTENDED option is set.
                    143: </P>
                    144: <P>
1.1.1.4 ! misho     145: 16. In PCRE, the upper/lower case character properties Lu and Ll are not
        !           146: affected when case-independent matching is specified. For example, \p{Lu}
        !           147: always matches an upper case letter. I think Perl has changed in this respect;
        !           148: in the release at the time of writing (5.16), \p{Lu} and \p{Ll} match all
        !           149: letters, regardless of case, when case independence is specified.
        !           150: </P>
        !           151: <P>
        !           152: 17. PCRE provides some extensions to the Perl regular expression facilities.
1.1       misho     153: Perl 5.10 includes new features that are not in earlier versions of Perl, some
                    154: of which (such as named parentheses) have been in PCRE for some time. This list
                    155: is with respect to Perl 5.10:
                    156: <br>
                    157: <br>
                    158: (a) Although lookbehind assertions in PCRE must match fixed length strings,
                    159: each alternative branch of a lookbehind assertion can match a different length
                    160: of string. Perl requires them all to have the same length.
                    161: <br>
                    162: <br>
                    163: (b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $
                    164: meta-character matches only at the very end of the string.
                    165: <br>
                    166: <br>
                    167: (c) If PCRE_EXTRA is set, a backslash followed by a letter with no special
                    168: meaning is faulted. Otherwise, like Perl, the backslash is quietly ignored.
                    169: (Perl can be made to issue a warning.)
                    170: <br>
                    171: <br>
                    172: (d) If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is
                    173: inverted, that is, by default they are not greedy, but if followed by a
                    174: question mark they are.
                    175: <br>
                    176: <br>
                    177: (e) PCRE_ANCHORED can be used at matching time to force a pattern to be tried
                    178: only at the first matching position in the subject string.
                    179: <br>
                    180: <br>
                    181: (f) The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART, and
                    182: PCRE_NO_AUTO_CAPTURE options for <b>pcre_exec()</b> have no Perl equivalents.
                    183: <br>
                    184: <br>
                    185: (g) The \R escape sequence can be restricted to match only CR, LF, or CRLF
                    186: by the PCRE_BSR_ANYCRLF option.
                    187: <br>
                    188: <br>
                    189: (h) The callout facility is PCRE-specific.
                    190: <br>
                    191: <br>
                    192: (i) The partial matching facility is PCRE-specific.
                    193: <br>
                    194: <br>
                    195: (j) Patterns compiled by PCRE can be saved and re-used at a later time, even on
                    196: different hosts that have the other endianness. However, this does not apply to
                    197: optimized data created by the just-in-time compiler.
                    198: <br>
                    199: <br>
1.1.1.4 ! misho     200: (k) The alternative matching functions (<b>pcre_dfa_exec()</b>,
        !           201: <b>pcre16_dfa_exec()</b> and <b>pcre32_dfa_exec()</b>,) match in a different way
        !           202: and are not Perl-compatible.
1.1       misho     203: <br>
                    204: <br>
                    205: (l) PCRE recognizes some special sequences such as (*CR) at the start of
                    206: a pattern that set overall options that cannot be changed within the pattern.
                    207: </P>
                    208: <br><b>
                    209: AUTHOR
                    210: </b><br>
                    211: <P>
                    212: Philip Hazel
                    213: <br>
                    214: University Computing Service
                    215: <br>
                    216: Cambridge CB2 3QH, England.
                    217: <br>
                    218: </P>
                    219: <br><b>
                    220: REVISION
                    221: </b><br>
                    222: <P>
1.1.1.4 ! misho     223: Last updated: 19 March 2013
1.1       misho     224: <br>
1.1.1.4 ! misho     225: Copyright &copy; 1997-2013 University of Cambridge.
1.1       misho     226: <br>
                    227: <p>
                    228: Return to the <a href="index.html">PCRE index page</a>.
                    229: </p>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>