"Fossies" - the Fresh Open Source Software Archive

Member "pcre2-10.36/doc/html/pcre2compat.html" (4 Dec 2020, 10808 Bytes) of package /linux/misc/pcre2-10.36.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <html>
    2 <head>
    3 <title>pcre2compat specification</title>
    4 </head>
    5 <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
    6 <h1>pcre2compat man page</h1>
    7 <p>
    8 Return to the <a href="index.html">PCRE2 index page</a>.
    9 </p>
   10 <p>
   11 This page is part of the PCRE2 HTML documentation. It was generated
   12 automatically from the original man page. If there is any nonsense in it,
   13 please consult the man page, in case the conversion went wrong.
   14 <br>
   15 <br><b>
   16 DIFFERENCES BETWEEN PCRE2 AND PERL
   17 </b><br>
   18 <P>
   19 This document describes some of the differences in the ways that PCRE2 and Perl
   20 handle regular expressions. The differences described here are with respect to
   21 Perl version 5.32.0, but as both Perl and PCRE2 are continually changing, the
   22 information may at times be out of date.
   23 </P>
   24 <P>
   25 1. PCRE2 has only a subset of Perl's Unicode support. Details of what it does
   26 have are given in the
   27 <a href="pcre2unicode.html"><b>pcre2unicode</b></a>
   28 page.
   29 </P>
   30 <P>
   31 2. Like Perl, PCRE2 allows repeat quantifiers on parenthesized assertions, but
   32 they do not mean what you might think. For example, (?!a){3} does not assert
   33 that the next three characters are not "a". It just asserts that the next
   34 character is not "a" three times (in principle; PCRE2 optimizes this to run the
   35 assertion just once). Perl allows some repeat quantifiers on other assertions,
   36 for example, \b* (but not \b{3}, though oddly it does allow ^{3}), but these
   37 do not seem to have any use. PCRE2 does not allow any kind of quantifier on
   38 non-lookaround assertions.
   39 </P>
   40 <P>
   41 3. Capture groups that occur inside negative lookaround assertions are counted,
   42 but their entries in the offsets vector are set only when a negative assertion
   43 is a condition that has a matching branch (that is, the condition is false).
   44 Perl may set such capture groups in other circumstances.
   45 </P>
   46 <P>
   47 4. The following Perl escape sequences are not supported: \F, \l, \L, \u,
   48 \U, and \N when followed by a character name. \N on its own, matching a
   49 non-newline character, and \N{U+dd..}, matching a Unicode code point, are
   50 supported. The escapes that modify the case of following letters are
   51 implemented by Perl's general string-handling and are not part of its pattern
   52 matching engine. If any of these are encountered by PCRE2, an error is
   53 generated by default. However, if either of the PCRE2_ALT_BSUX or
   54 PCRE2_EXTRA_ALT_BSUX options is set, \U and \u are interpreted as ECMAScript
   55 interprets them.
   56 </P>
   57 <P>
   58 5. The Perl escape sequences \p, \P, and \X are supported only if PCRE2 is
   59 built with Unicode support (the default). The properties that can be tested
   60 with \p and \P are limited to the general category properties such as Lu and
   61 Nd, script names such as Greek or Han, and the derived properties Any and L&.
   62 Both PCRE2 and Perl support the Cs (surrogate) property, but in PCRE2 its use
   63 is limited. See the
   64 <a href="pcre2pattern.html"><b>pcre2pattern</b></a>
   65 documentation for details. The long synonyms for property names that Perl
   66 supports (such as \p{Letter}) are not supported by PCRE2, nor is it permitted
   67 to prefix any of these properties with "Is".
   68 </P>
   69 <P>
   70 6. PCRE2 supports the \Q...\E escape for quoting substrings. Characters
   71 in between are treated as literals. However, this is slightly different from
   72 Perl in that $ and @ are also handled as literals inside the quotes. In Perl,
   73 they cause variable interpolation (but of course PCRE2 does not have
   74 variables). Also, Perl does "double-quotish backslash interpolation" on any
   75 backslashes between \Q and \E which, its documentation says, "may lead to
   76 confusing results". PCRE2 treats a backslash between \Q and \E just like any
   77 other character. Note the following examples:
   78 <pre>
   79     Pattern            PCRE2 matches     Perl matches
   80 
   81     \Qabc$xyz\E        abc$xyz           abc followed by the contents of $xyz
   82     \Qabc\$xyz\E       abc\$xyz          abc\$xyz
   83     \Qabc\E\$\Qxyz\E   abc$xyz           abc$xyz
   84     \QA\B\E            A\B               A\B
   85     \Q\\E              \                 \\E
   86 </pre>
   87 The \Q...\E sequence is recognized both inside and outside character classes
   88 by both PCRE2 and Perl.
   89 </P>
   90 <P>
   91 7. Fairly obviously, PCRE2 does not support the (?{code}) and (??{code})
   92 constructions. However, PCRE2 does have a "callout" feature, which allows an
   93 external function to be called during pattern matching. See the
   94 <a href="pcre2callout.html"><b>pcre2callout</b></a>
   95 documentation for details.
   96 </P>
   97 <P>
   98 8. Subroutine calls (whether recursive or not) were treated as atomic groups up
   99 to PCRE2 release 10.23, but from release 10.30 this changed, and backtracking
  100 into subroutine calls is now supported, as in Perl.
  101 </P>
  102 <P>
  103 9. In PCRE2, if any of the backtracking control verbs are used in a group that
  104 is called as a subroutine (whether or not recursively), their effect is
  105 confined to that group; it does not extend to the surrounding pattern. This is
  106 not always the case in Perl. In particular, if (*THEN) is present in a group
  107 that is called as a subroutine, its action is limited to that group, even if
  108 the group does not contain any | characters. Note that such groups are
  109 processed as anchored at the point where they are tested.
  110 </P>
  111 <P>
  112 10. 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 PCRE2, but there are cases where it differs.
  117 </P>
  118 <P>
  119 11. There are some differences that are concerned with the settings of captured
  120 strings when part of a pattern is repeated. For example, matching "aba" against
  121 the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE2 it is set to
  122 "b".
  123 </P>
  124 <P>
  125 12. PCRE2's handling of duplicate capture group numbers and names is not as
  126 general as Perl's. This is a consequence of the fact the PCRE2 works internally
  127 just with numbers, using an external table to translate between numbers and
  128 names. In particular, a pattern such as (?|(?&#60;a&#62;A)|(?&#60;b&#62;B)), where the two
  129 capture groups have the same number but different names, is not supported, and
  130 causes an error at compile time. If it were allowed, it would not be possible
  131 to distinguish which group matched, because both names map to capture group
  132 number 1. To avoid this confusing situation, an error is given at compile time.
  133 </P>
  134 <P>
  135 13. Perl used to recognize comments in some places that PCRE2 does not, for
  136 example, between the ( and ? at the start of a group. If the /x modifier is
  137 set, Perl allowed white space between ( and ? though the latest Perls give an
  138 error (for a while it was just deprecated). There may still be some cases where
  139 Perl behaves differently.
  140 </P>
  141 <P>
  142 14. Perl, when in warning mode, gives warnings for character classes such as
  143 [A-\d] or [a-[:digit:]]. It then treats the hyphens as literals. PCRE2 has no
  144 warning features, so it gives an error in these cases because they are almost
  145 certainly user mistakes.
  146 </P>
  147 <P>
  148 15. In PCRE2, the upper/lower case character properties Lu and Ll are not
  149 affected when case-independent matching is specified. For example, \p{Lu}
  150 always matches an upper case letter. I think Perl has changed in this respect;
  151 in the release at the time of writing (5.32), \p{Lu} and \p{Ll} match all
  152 letters, regardless of case, when case independence is specified.
  153 </P>
  154 <P>
  155 16. From release 5.32.0, Perl locks out the use of \K in lookaround
  156 assertions. In PCRE2, \K is acted on when it occurs in positive assertions,
  157 but is ignored in negative assertions.
  158 </P>
  159 <P>
  160 17. PCRE2 provides some extensions to the Perl regular expression facilities.
  161 Perl 5.10 included new features that were not in earlier versions of Perl, some
  162 of which (such as named parentheses) were in PCRE2 for some time before. This
  163 list is with respect to Perl 5.32:
  164 <br>
  165 <br>
  166 (a) Although lookbehind assertions in PCRE2 must match fixed length strings,
  167 each alternative toplevel branch of a lookbehind assertion can match a
  168 different length of string. Perl requires them all to have the same length.
  169 <br>
  170 <br>
  171 (b) From PCRE2 10.23, backreferences to groups of fixed length are supported
  172 in lookbehinds, provided that there is no possibility of referencing a
  173 non-unique number or name. Perl does not support backreferences in lookbehinds.
  174 <br>
  175 <br>
  176 (c) If PCRE2_DOLLAR_ENDONLY is set and PCRE2_MULTILINE is not set, the $
  177 meta-character matches only at the very end of the string.
  178 <br>
  179 <br>
  180 (d) A backslash followed by a letter with no special meaning is faulted. (Perl
  181 can be made to issue a warning.)
  182 <br>
  183 <br>
  184 (e) If PCRE2_UNGREEDY is set, the greediness of the repetition quantifiers is
  185 inverted, that is, by default they are not greedy, but if followed by a
  186 question mark they are.
  187 <br>
  188 <br>
  189 (f) PCRE2_ANCHORED can be used at matching time to force a pattern to be tried
  190 only at the first matching position in the subject string.
  191 <br>
  192 <br>
  193 (g) The PCRE2_NOTBOL, PCRE2_NOTEOL, PCRE2_NOTEMPTY and PCRE2_NOTEMPTY_ATSTART
  194 options have no Perl equivalents.
  195 <br>
  196 <br>
  197 (h) The \R escape sequence can be restricted to match only CR, LF, or CRLF
  198 by the PCRE2_BSR_ANYCRLF option.
  199 <br>
  200 <br>
  201 (i) The callout facility is PCRE2-specific. Perl supports codeblocks and
  202 variable interpolation, but not general hooks on every match.
  203 <br>
  204 <br>
  205 (j) The partial matching facility is PCRE2-specific.
  206 <br>
  207 <br>
  208 (k) The alternative matching function (<b>pcre2_dfa_match()</b> matches in a
  209 different way and is not Perl-compatible.
  210 <br>
  211 <br>
  212 (l) PCRE2 recognizes some special sequences such as (*CR) or (*NO_JIT) at
  213 the start of a pattern. These set overall options that cannot be changed within
  214 the pattern.
  215 <br>
  216 <br>
  217 (m) PCRE2 supports non-atomic positive lookaround assertions. This is an
  218 extension to the lookaround facilities. The default, Perl-compatible
  219 lookarounds are atomic.
  220 </P>
  221 <P>
  222 18. The Perl /a modifier restricts /d numbers to pure ascii, and the /aa
  223 modifier restricts /i case-insensitive matching to pure ascii, ignoring Unicode
  224 rules. This separation cannot be represented with PCRE2_UCP.
  225 </P>
  226 <P>
  227 19. Perl has different limits than PCRE2. See the
  228 <a href="pcre2limit.html"><b>pcre2limit</b></a>
  229 documentation for details. Perl went with 5.10 from recursion to iteration
  230 keeping the intermediate matches on the heap, which is ~10% slower but does not
  231 fall into any stack-overflow limit. PCRE2 made a similar change at release
  232 10.30, and also has many build-time and run-time customizable limits.
  233 </P>
  234 <br><b>
  235 AUTHOR
  236 </b><br>
  237 <P>
  238 Philip Hazel
  239 <br>
  240 University Computing Service
  241 <br>
  242 Cambridge, England.
  243 <br>
  244 </P>
  245 <br><b>
  246 REVISION
  247 </b><br>
  248 <P>
  249 Last updated: 06 October 2020
  250 <br>
  251 Copyright &copy; 1997-2019 University of Cambridge.
  252 <br>
  253 <p>
  254 Return to the <a href="index.html">PCRE2 index page</a>.
  255 </p>