/[pcre]/code/trunk/doc/html/pcrecompat.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcrecompat.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 91 by nigel, Sat Feb 24 21:41:34 2007 UTC revision 461 by ph10, Mon Oct 5 10:59:35 2009 UTC
# Line 18  DIFFERENCES BETWEEN PCRE AND PERL Line 18  DIFFERENCES BETWEEN PCRE AND PERL
18  <P>  <P>
19  This document describes the differences in the ways that PCRE and Perl handle  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  regular expressions. The differences described here are with respect to Perl
21  5.8.  5.10.
22  </P>  </P>
23  <P>  <P>
24  1. PCRE has only a subset of Perl's UTF-8 and Unicode support. Details of what  1. PCRE has only a subset of Perl's UTF-8 and Unicode support. Details of what
# Line 58  encountered by PCRE, an error is generat Line 58  encountered by PCRE, an error is generat
58  built with Unicode character property support. The properties that can be  built with Unicode character property support. The properties that can be
59  tested with \p and \P are limited to the general category properties such as  tested with \p and \P are limited to the general category properties such as
60  Lu and Nd, script names such as Greek or Han, and the derived properties Any  Lu and Nd, script names such as Greek or Han, and the derived properties Any
61  and L&.  and L&. PCRE does support the Cs (surrogate) property, which Perl does not; the
62    Perl documentation says "Because Perl hides the need for the user to understand
63    the internal representation of Unicode characters, there is no need to
64    implement the somewhat messy concept of surrogates."
65  </P>  </P>
66  <P>  <P>
67  7. PCRE does support the \Q...\E escape for quoting substrings. Characters in  7. PCRE does support the \Q...\E escape for quoting substrings. Characters in
# Line 76  following examples: Line 79  following examples:
79  The \Q...\E sequence is recognized both inside and outside character classes.  The \Q...\E sequence is recognized both inside and outside character classes.
80  </P>  </P>
81  <P>  <P>
82  8. Fairly obviously, PCRE does not support the (?{code}) and (?p{code})  8. Fairly obviously, PCRE does not support the (?{code}) and (??{code})
83  constructions. However, there is support for recursive patterns using the  constructions. However, there is support for recursive patterns. This is not
84  non-Perl items (?R), (?number), and (?P&#62;name). Also, the PCRE "callout" feature  available in Perl 5.8, but it is in Perl 5.10. Also, the PCRE "callout"
85  allows an external function to be called during pattern matching. See the  feature allows an external function to be called during pattern matching. See
86    the
87  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
88  documentation for details.  documentation for details.
89  </P>  </P>
90  <P>  <P>
91  9. There are some differences that are concerned with the settings of captured  9. Subpatterns that are called recursively or as "subroutines" are always
92    treated as atomic groups in PCRE. This is like Python, but unlike Perl. There
93    is a discussion of an example that explains this in more detail in the
94    <a href="pcrepattern.html#recursiondifference">section on recursion differences from Perl</a>
95    in the
96    <a href="pcrepattern.html"><b>pcrepattern</b></a>
97    page.
98    </P>
99    <P>
100    10. There are some differences that are concerned with the settings of captured
101  strings when part of a pattern is repeated. For example, matching "aba" against  strings when part of a pattern is repeated. For example, matching "aba" against
102  the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE it is set to "b".  the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE it is set to "b".
103  </P>  </P>
104  <P>  <P>
105  10. PCRE provides some extensions to the Perl regular expression facilities:  11. PCRE does support Perl 5.10's backtracking verbs (*ACCEPT), (*FAIL), (*F),
106  <br>  (*COMMIT), (*PRUNE), (*SKIP), and (*THEN), but only in the forms without an
107  <br>  argument. PCRE does not support (*MARK).
108  (a) Although lookbehind assertions must match fixed length strings, each  </P>
109  alternative branch of a lookbehind assertion can match a different length of  <P>
110  string. Perl requires them all to have the same length.  12. PCRE's handling of duplicate subpattern numbers and duplicate subpattern
111    names is not as general as Perl's. This is a consequence of the fact the PCRE
112    works internally just with numbers, using an external table to translate
113    between numbers and names. In particular, a pattern such as (?|(?&#60;a&#62;A)|(?&#60;b)B),
114    where the two capturing parentheses have the same number but different names,
115    is not supported, and causes an error at compile time. If it were allowed, it
116    would not be possible to distinguish which parentheses matched, because both
117    names map to capturing subpattern number 1. To avoid this confusing situation,
118    an error is given at compile time.
119    </P>
120    <P>
121    13. PCRE provides some extensions to the Perl regular expression facilities.
122    Perl 5.10 includes new features that are not in earlier versions of Perl, some
123    of which (such as named parentheses) have been in PCRE for some time. This list
124    is with respect to Perl 5.10:
125    <br>
126    <br>
127    (a) Although lookbehind assertions in PCRE must match fixed length strings,
128    each alternative branch of a lookbehind assertion can match a different length
129    of string. Perl requires them all to have the same length.
130  <br>  <br>
131  <br>  <br>
132  (b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $  (b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $
# Line 102  meta-character matches only at the very Line 134  meta-character matches only at the very
134  <br>  <br>
135  <br>  <br>
136  (c) If PCRE_EXTRA is set, a backslash followed by a letter with no special  (c) If PCRE_EXTRA is set, a backslash followed by a letter with no special
137  meaning is faulted. Otherwise, like Perl, the backslash is ignored. (Perl can  meaning is faulted. Otherwise, like Perl, the backslash is quietly ignored.
138  be made to issue a warning.)  (Perl can be made to issue a warning.)
139  <br>  <br>
140  <br>  <br>
141  (d) If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is  (d) If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is
# Line 115  question mark they are. Line 147  question mark they are.
147  only at the first matching position in the subject string.  only at the first matching position in the subject string.
148  <br>  <br>
149  <br>  <br>
150  (f) The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NO_AUTO_CAPTURE  (f) The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART, and
151  options for <b>pcre_exec()</b> have no Perl equivalents.  PCRE_NO_AUTO_CAPTURE options for <b>pcre_exec()</b> have no Perl equivalents.
 <br>  
152  <br>  <br>
 (g) The (?R), (?number), and (?P&#62;name) constructs allows for recursive pattern  
 matching (Perl can do this using the (?p{code}) construct, which PCRE cannot  
 support.)  
153  <br>  <br>
154    (g) The \R escape sequence can be restricted to match only CR, LF, or CRLF
155    by the PCRE_BSR_ANYCRLF option.
156  <br>  <br>
 (h) PCRE supports named capturing substrings, using the Python syntax.  
157  <br>  <br>
158    (h) The callout facility is PCRE-specific.
159  <br>  <br>
 (i) PCRE supports the possessive quantifier "++" syntax, taken from Sun's Java  
 package.  
160  <br>  <br>
161    (i) The partial matching facility is PCRE-specific.
162  <br>  <br>
 (j) The (R) condition, for testing recursion, is a PCRE extension.  
163  <br>  <br>
164    (j) Patterns compiled by PCRE can be saved and re-used at a later time, even on
165    different hosts that have the other endianness.
166  <br>  <br>
 (k) The callout facility is PCRE-specific.  
167  <br>  <br>
168    (k) The alternative matching function (<b>pcre_dfa_exec()</b>) matches in a
169    different way and is not Perl-compatible.
170  <br>  <br>
 (l) The partial matching facility is PCRE-specific.  
171  <br>  <br>
172    (l) PCRE recognizes some special sequences such as (*CR) at the start of
173    a pattern that set overall options that cannot be changed within the pattern.
174    </P>
175    <br><b>
176    AUTHOR
177    </b><br>
178    <P>
179    Philip Hazel
180  <br>  <br>
181  (m) Patterns compiled by PCRE can be saved and re-used at a later time, even on  University Computing Service
 different hosts that have the other endianness.  
182  <br>  <br>
183    Cambridge CB2 3QH, England.
184  <br>  <br>
 (n) The alternative matching function (<b>pcre_dfa_exec()</b>) matches in a  
 different way and is not Perl-compatible.  
185  </P>  </P>
186    <br><b>
187    REVISION
188    </b><br>
189  <P>  <P>
190  Last updated: 06 June 2006  Last updated: 04 October 2009
191    <br>
192    Copyright &copy; 1997-2009 University of Cambridge.
193  <br>  <br>
 Copyright &copy; 1997-2006 University of Cambridge.  
194  <p>  <p>
195  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.
196  </p>  </p>

Legend:
Removed from v.91  
changed lines
  Added in v.461

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12