ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 73 - (hide annotations) (download)
Sat Feb 24 21:40:30 2007 UTC (8 years, 2 months ago) by nigel
File size: 4355 byte(s)
Load pcre-4.5 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 nigel 73 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.
23     2. PCRE does not allow repeat quantifiers on lookahead assertions. Perl permits
24 nigel 63 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.
28 nigel 73 3. Capturing subpatterns that occur inside negative lookahead assertions are
29 nigel 63 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.
34 nigel 73 4. Though binary zero characters are supported in the subject string, they are
35 nigel 63 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.
39 nigel 73 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 nigel 63 string-handling and are not part of its pattern matching engine. If any of
42     these are encountered by PCRE, an error is generated.
44 nigel 73 6. PCRE does support the \\Q...\\E escape for quoting substrings. Characters in
45 nigel 63 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:
50     Pattern PCRE matches Perl matches
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
57 nigel 73 The \\Q...\\E sequence is recognized both inside and outside character classes.
58 nigel 63
59 nigel 73 7. Fairly obviously, PCRE does not support the (?{code}) and (?p{code})
60 nigel 63 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.
65 nigel 73 8. There are some differences that are concerned with the settings of captured
66 nigel 63 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".
69 nigel 73 9. PCRE provides some extensions to the Perl regular expression facilities:
70 nigel 63
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.
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.
78     (c) If PCRE_EXTRA is set, a backslash followed by a letter with no special
79     meaning is faulted.
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.
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.
89     options for \fBpcre_exec()\fR have no Perl equivalents.
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.)
95     (h) PCRE supports named capturing substrings, using the Python syntax.
97     (i) PCRE supports the possessive quantifier "++" syntax, taken from Sun's Java
98     package.
100     (j) The (R) condition, for testing recursion, is a PCRE extension.
102     (k) The callout facility is PCRE-specific.
104     .in 0
105 nigel 73 Last updated: 09 December 2003
106 nigel 63 .br
107     Copyright (c) 1997-2003 University of Cambridge.

ViewVC Help
Powered by ViewVC 1.1.12