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, 1 month 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
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.
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.
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.
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.
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.
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:
38     Pattern PCRE matches Perl matches
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
45     In PCRE, the \\Q...\\E mechanism is not recognized inside a character class.
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.
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".
57     10. PCRE provides some extensions to the Perl regular expression facilities:
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.
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.
66     (c) If PCRE_EXTRA is set, a backslash followed by a letter with no special
67     meaning is faulted.
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.
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.
77     options for \fBpcre_exec()\fR have no Perl equivalents.
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.)
83     (h) PCRE supports named capturing substrings, using the Python syntax.
85     (i) PCRE supports the possessive quantifier "++" syntax, taken from Sun's Java
86     package.
88     (j) The (R) condition, for testing recursion, is a PCRE extension.
90     (k) The callout facility is PCRE-specific.
92     .in 0
93     Last updated: 03 February 2003
94     .br
95     Copyright (c) 1997-2003 University of Cambridge.

ViewVC Help
Powered by ViewVC 1.1.12