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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 63 - (hide annotations) (download)
Sat Feb 24 21:40:03 2007 UTC (7 years, 6 months ago) by nigel
File size: 4141 byte(s)
Load pcre-4.0 into code/trunk.

1 nigel 63 .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 allow repeat quantifiers on lookahead assertions. Perl permits
12     them, but they do not mean what you might think. For example, (?!a){3} does
13     not assert that the next three characters are not "a". It just asserts that the
14     next character is not "a" three times.
15    
16     2. Capturing subpatterns that occur inside negative lookahead assertions are
17     counted, but their entries in the offsets vector are never set. Perl sets its
18     numerical variables from any such patterns that are matched before the
19     assertion fails to match something (thereby succeeding), but only if the
20     negative lookahead assertion contains just one branch.
21    
22     3. Though binary zero characters are supported in the subject string, they are
23     not allowed in a pattern string because it is passed as a normal C string,
24     terminated by zero. The escape sequence "\\0" can be used in the pattern to
25     represent a binary zero.
26    
27     4. The following Perl escape sequences are not supported: \\l, \\u, \\L,
28     \\U, \\P, \\p, \N, and \\X. In fact these are implemented by Perl's general
29     string-handling and are not part of its pattern matching engine. If any of
30     these are encountered by PCRE, an error is generated.
31    
32     5. PCRE does support the \\Q...\\E escape for quoting substrings. Characters in
33     between are treated as literals. This is slightly different from Perl in that $
34     and @ are also handled as literals inside the quotes. In Perl, they cause
35     variable interpolation (but of course PCRE does not have variables). Note the
36     following examples:
37    
38     Pattern PCRE matches Perl matches
39    
40     \\Qabc$xyz\\E abc$xyz abc followed by the
41     contents of $xyz
42     \\Qabc\\$xyz\\E abc\\$xyz abc\\$xyz
43     \\Qabc\\E\\$\\Qxyz\\E abc$xyz abc$xyz
44    
45     In PCRE, the \\Q...\\E mechanism is not recognized inside a character class.
46    
47     8. Fairly obviously, PCRE does not support the (?{code}) and (?p{code})
48     constructions. However, there is some experimental support for recursive
49     patterns using the non-Perl items (?R), (?number) and (?P>name). Also, the PCRE
50     "callout" feature allows an external function to be called during pattern
51     matching.
52    
53     9. There are some differences that are concerned with the settings of captured
54     strings when part of a pattern is repeated. For example, matching "aba" against
55     the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE it is set to "b".
56    
57     10. PCRE provides some extensions to the Perl regular expression facilities:
58    
59     (a) Although lookbehind assertions must match fixed length strings, each
60     alternative branch of a lookbehind assertion can match a different length of
61     string. Perl requires them all to have the same length.
62    
63     (b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $
64     meta-character matches only at the very end of the string.
65    
66     (c) If PCRE_EXTRA is set, a backslash followed by a letter with no special
67     meaning is faulted.
68    
69     (d) If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is
70     inverted, that is, by default they are not greedy, but if followed by a
71     question mark they are.
72    
73     (e) PCRE_ANCHORED can be used to force a pattern to be tried only at the first
74     matching position in the subject string.
75    
76     (f) The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NO_AUTO_CAPTURE
77     options for \fBpcre_exec()\fR have no Perl equivalents.
78    
79     (g) The (?R), (?number), and (?P>name) constructs allows for recursive pattern
80     matching (Perl can do this using the (?p{code}) construct, which PCRE cannot
81     support.)
82    
83     (h) PCRE supports named capturing substrings, using the Python syntax.
84    
85     (i) PCRE supports the possessive quantifier "++" syntax, taken from Sun's Java
86     package.
87    
88     (j) The (R) condition, for testing recursion, is a PCRE extension.
89    
90     (k) The callout facility is PCRE-specific.
91    
92     .in 0
93     Last updated: 03 February 2003
94     .br
95     Copyright (c) 1997-2003 University of Cambridge.

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12