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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 63 - (show annotations) (download) (as text)
Sat Feb 24 21:40:03 2007 UTC (7 years, 1 month ago) by nigel
File MIME type: text/html
File size: 4704 byte(s)
Load pcre-4.0 into code/trunk.

1 <html>
2 <head>
3 <title>pcrecompat specification</title>
4 </head>
5 <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
6 This HTML document has been generated automatically from the original man page.
7 If there is any nonsense in it, please consult the man page, in case the
8 conversion went wrong.<br>
9 <ul>
10 <li><a name="TOC1" href="#SEC1">DIFFERENCES FROM PERL</a>
11 </ul>
12 <br><a name="SEC1" href="#TOC1">DIFFERENCES FROM PERL</a><br>
13 <P>
14 This document describes the differences in the ways that PCRE and Perl handle
15 regular expressions. The differences described here are with respect to Perl
16 5.8.
17 </P>
18 <P>
19 1. PCRE does not allow repeat quantifiers on lookahead assertions. Perl permits
20 them, but they do not mean what you might think. For example, (?!a){3} does
21 not assert that the next three characters are not "a". It just asserts that the
22 next character is not "a" three times.
23 </P>
24 <P>
25 2. Capturing subpatterns that occur inside negative lookahead assertions are
26 counted, but their entries in the offsets vector are never set. Perl sets its
27 numerical variables from any such patterns that are matched before the
28 assertion fails to match something (thereby succeeding), but only if the
29 negative lookahead assertion contains just one branch.
30 </P>
31 <P>
32 3. Though binary zero characters are supported in the subject string, they are
33 not allowed in a pattern string because it is passed as a normal C string,
34 terminated by zero. The escape sequence "\0" can be used in the pattern to
35 represent a binary zero.
36 </P>
37 <P>
38 4. The following Perl escape sequences are not supported: \l, \u, \L,
39 \U, \P, \p, \N, and \X. In fact these are implemented by Perl's general
40 string-handling and are not part of its pattern matching engine. If any of
41 these are encountered by PCRE, an error is generated.
42 </P>
43 <P>
44 5. PCRE does support the \Q...\E escape for quoting substrings. Characters in
45 between are treated as literals. This is slightly different from Perl in that $
46 and @ are also handled as literals inside the quotes. In Perl, they cause
47 variable interpolation (but of course PCRE does not have variables). Note the
48 following examples:
49 </P>
50 <P>
51 <pre>
52 Pattern PCRE matches Perl matches
53 </PRE>
54 </P>
55 <P>
56 <pre>
57 \Qabc$xyz\E abc$xyz abc followed by the
58 contents of $xyz
59 \Qabc\$xyz\E abc\$xyz abc\$xyz
60 \Qabc\E\$\Qxyz\E abc$xyz abc$xyz
61 </PRE>
62 </P>
63 <P>
64 In PCRE, the \Q...\E mechanism is not recognized inside a character class.
65 </P>
66 <P>
67 8. Fairly obviously, PCRE does not support the (?{code}) and (?p{code})
68 constructions. However, there is some experimental support for recursive
69 patterns using the non-Perl items (?R), (?number) and (?P&#62;name). Also, the PCRE
70 "callout" feature allows an external function to be called during pattern
71 matching.
72 </P>
73 <P>
74 9. There are some differences that are concerned with the settings of captured
75 strings when part of a pattern is repeated. For example, matching "aba" against
76 the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE it is set to "b".
77 </P>
78 <P>
79 10. PCRE provides some extensions to the Perl regular expression facilities:
80 </P>
81 <P>
82 (a) Although lookbehind assertions must match fixed length strings, each
83 alternative branch of a lookbehind assertion can match a different length of
84 string. Perl requires them all to have the same length.
85 </P>
86 <P>
87 (b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $
88 meta-character matches only at the very end of the string.
89 </P>
90 <P>
91 &copy; If PCRE_EXTRA is set, a backslash followed by a letter with no special
92 meaning is faulted.
93 </P>
94 <P>
95 (d) If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is
96 inverted, that is, by default they are not greedy, but if followed by a
97 question mark they are.
98 </P>
99 <P>
100 (e) PCRE_ANCHORED can be used to force a pattern to be tried only at the first
101 matching position in the subject string.
102 </P>
103 <P>
104 (f) The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NO_AUTO_CAPTURE
105 options for <b>pcre_exec()</b> have no Perl equivalents.
106 </P>
107 <P>
108 (g) The (?R), (?number), and (?P&#62;name) constructs allows for recursive pattern
109 matching (Perl can do this using the (?p{code}) construct, which PCRE cannot
110 support.)
111 </P>
112 <P>
113 (h) PCRE supports named capturing substrings, using the Python syntax.
114 </P>
115 <P>
116 (i) PCRE supports the possessive quantifier "++" syntax, taken from Sun's Java
117 package.
118 </P>
119 <P>
120 (j) The (R) condition, for testing recursion, is a PCRE extension.
121 </P>
122 <P>
123 (k) The callout facility is PCRE-specific.
124 </P>
125 <P>
126 Last updated: 03 February 2003
127 <br>
128 Copyright &copy; 1997-2003 University of Cambridge.

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12