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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 73 - (show annotations)
Sat Feb 24 21:40:30 2007 UTC (8 years, 6 months ago) by nigel
File size: 4355 byte(s)
Error occurred while calculating annotation data.
Load pcre-4.5 into code/trunk.
1 .TH PCRE 3
2 .SH NAME
3 PCRE - Perl-compatible regular expressions
4 .SH DIFFERENCES FROM PERL
5 .rs
6 .sp
7 This document describes the differences in the ways that PCRE and Perl handle
8 regular expressions. The differences described here are with respect to Perl
9 5.8.
10
11 1. PCRE does not have full UTF-8 support. Details of what it does have are
12 given in the
13 .\" HTML <a href="pcre.html#utf8support">
14 .\" </a>
15 section on UTF-8 support
16 .\"
17 in the main
18 .\" HREF
19 \fBpcre\fR
20 .\"
21 page.
22
23 2. PCRE does not allow repeat quantifiers on lookahead assertions. Perl permits
24 them, but they do not mean what you might think. For example, (?!a){3} does
25 not assert that the next three characters are not "a". It just asserts that the
26 next character is not "a" three times.
27
28 3. Capturing subpatterns that occur inside negative lookahead assertions are
29 counted, but their entries in the offsets vector are never set. Perl sets its
30 numerical variables from any such patterns that are matched before the
31 assertion fails to match something (thereby succeeding), but only if the
32 negative lookahead assertion contains just one branch.
33
34 4. Though binary zero characters are supported in the subject string, they are
35 not allowed in a pattern string because it is passed as a normal C string,
36 terminated by zero. The escape sequence "\\0" can be used in the pattern to
37 represent a binary zero.
38
39 5. The following Perl escape sequences are not supported: \\l, \\u, \\L,
40 \\U, \\P, \\p, \\N, and \\X. In fact these are implemented by Perl's general
41 string-handling and are not part of its pattern matching engine. If any of
42 these are encountered by PCRE, an error is generated.
43
44 6. 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
50 Pattern PCRE matches Perl matches
51
52 \\Qabc$xyz\\E abc$xyz abc followed by the
53 contents of $xyz
54 \\Qabc\\$xyz\\E abc\\$xyz abc\\$xyz
55 \\Qabc\\E\\$\\Qxyz\\E abc$xyz abc$xyz
56
57 The \\Q...\\E sequence is recognized both inside and outside character classes.
58
59 7. Fairly obviously, PCRE does not support the (?{code}) and (?p{code})
60 constructions. However, there is some experimental support for recursive
61 patterns using the non-Perl items (?R), (?number) and (?P>name). Also, the PCRE
62 "callout" feature allows an external function to be called during pattern
63 matching.
64
65 8. There are some differences that are concerned with the settings of captured
66 strings when part of a pattern is repeated. For example, matching "aba" against
67 the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE it is set to "b".
68
69 9. PCRE provides some extensions to the Perl regular expression facilities:
70
71 (a) Although lookbehind assertions must match fixed length strings, each
72 alternative branch of a lookbehind assertion can match a different length of
73 string. Perl requires them all to have the same length.
74
75 (b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $
76 meta-character matches only at the very end of the string.
77
78 (c) If PCRE_EXTRA is set, a backslash followed by a letter with no special
79 meaning is faulted.
80
81 (d) If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is
82 inverted, that is, by default they are not greedy, but if followed by a
83 question mark they are.
84
85 (e) PCRE_ANCHORED can be used to force a pattern to be tried only at the first
86 matching position in the subject string.
87
88 (f) The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NO_AUTO_CAPTURE
89 options for \fBpcre_exec()\fR have no Perl equivalents.
90
91 (g) The (?R), (?number), and (?P>name) constructs allows for recursive pattern
92 matching (Perl can do this using the (?p{code}) construct, which PCRE cannot
93 support.)
94
95 (h) PCRE supports named capturing substrings, using the Python syntax.
96
97 (i) PCRE supports the possessive quantifier "++" syntax, taken from Sun's Java
98 package.
99
100 (j) The (R) condition, for testing recursion, is a PCRE extension.
101
102 (k) The callout facility is PCRE-specific.
103
104 .in 0
105 Last updated: 09 December 2003
106 .br
107 Copyright (c) 1997-2003 University of Cambridge.

  ViewVC Help
Powered by ViewVC 1.1.5