/[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 96 by nigel, Fri Mar 2 13:10:43 2007 UTC revision 461 by ph10, Mon Oct 5 10:59:35 2009 UTC
# Line 17  DIFFERENCES BETWEEN PCRE AND PERL Line 17  DIFFERENCES BETWEEN PCRE AND PERL
17  </b><br>  </b><br>
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 mainly with respect to  regular expressions. The differences described here are with respect to Perl
21  Perl 5.8, though PCRE version 7.0 contains some features that are expected to  5.10.
 be in the forthcoming Perl 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 59  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 79  The \Q...\E sequence is recognized both Line 81  The \Q...\E sequence is recognized both
81  <P>  <P>
82  8. Fairly obviously, PCRE does not support the (?{code}) and (??{code})  8. Fairly obviously, PCRE does not support the (?{code}) and (??{code})
83  constructions. However, there is support for recursive patterns. This is not  constructions. However, there is support for recursive patterns. This is not
84  available in Perl 5.8, but will be in Perl 5.10. Also, the PCRE "callout"  available in Perl 5.8, but it is in Perl 5.10. Also, the PCRE "callout"
85  feature allows an external function to be called during pattern matching. See  feature allows an external function to be called during pattern matching. See
86  the  the
87  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
# Line 87  documentation for details. Line 89  documentation for details.
89  </P>  </P>
90  <P>  <P>
91  9. Subpatterns that are called recursively or as "subroutines" are always  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.  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>  </P>
99  <P>  <P>
100  10. There are some differences that are concerned with the settings of captured  10. There are some differences that are concerned with the settings of captured
# Line 95  strings when part of a pattern is repeat Line 102  strings when part of a pattern is repeat
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  11. PCRE provides some extensions to the Perl regular expression facilities.  11. PCRE does support Perl 5.10's backtracking verbs (*ACCEPT), (*FAIL), (*F),
106  Perl 5.10 will include new features that are not in earlier versions, some of  (*COMMIT), (*PRUNE), (*SKIP), and (*THEN), but only in the forms without an
107  which (such as named parentheses) have been in PCRE for some time. This list is  argument. PCRE does not support (*MARK).
108  with respect to Perl 5.10:  </P>
109  <br>  <P>
110  <br>  12. PCRE's handling of duplicate subpattern numbers and duplicate subpattern
111  (a) Although lookbehind assertions must match fixed length strings, each  names is not as general as Perl's. This is a consequence of the fact the PCRE
112  alternative branch of a lookbehind assertion can match a different length of  works internally just with numbers, using an external table to translate
113  string. Perl requires them all to have the same length.  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 111  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 124  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.
152    <br>
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>
 (g) The callout facility is PCRE-specific.  
157  <br>  <br>
158    (h) The callout facility is PCRE-specific.
159  <br>  <br>
 (h) The partial matching facility is PCRE-specific.  
160  <br>  <br>
161    (i) The partial matching facility is PCRE-specific.
162  <br>  <br>
163  (i) Patterns compiled by PCRE can be saved and re-used at a later time, even on  <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.  different hosts that have the other endianness.
166  <br>  <br>
167  <br>  <br>
168  (j) The alternative matching function (<b>pcre_dfa_exec()</b>) matches in a  (k) The alternative matching function (<b>pcre_dfa_exec()</b>) matches in a
169  different way and is not Perl-compatible.  different way and is not Perl-compatible.
170    <br>
171    <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>  </P>
175    <br><b>
176    AUTHOR
177    </b><br>
178  <P>  <P>
179  Last updated: 28 November 2006  Philip Hazel
180    <br>
181    University Computing Service
182    <br>
183    Cambridge CB2 3QH, England.
184    <br>
185    </P>
186    <br><b>
187    REVISION
188    </b><br>
189    <P>
190    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.96  
changed lines
  Added in v.461

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12