| 8 |
regular expressions. The differences described here are with respect to Perl |
regular expressions. The differences described here are with respect to Perl |
| 9 |
5.8. |
5.8. |
| 10 |
|
|
| 11 |
1. PCRE does not allow repeat quantifiers on lookahead assertions. Perl permits |
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 |
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 |
not assert that the next three characters are not "a". It just asserts that the |
| 26 |
next character is not "a" three times. |
next character is not "a" three times. |
| 27 |
|
|
| 28 |
2. Capturing subpatterns that occur inside negative lookahead assertions are |
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 |
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 |
numerical variables from any such patterns that are matched before the |
| 31 |
assertion fails to match something (thereby succeeding), but only if the |
assertion fails to match something (thereby succeeding), but only if the |
| 32 |
negative lookahead assertion contains just one branch. |
negative lookahead assertion contains just one branch. |
| 33 |
|
|
| 34 |
3. Though binary zero characters are supported in the subject string, they are |
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, |
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 |
terminated by zero. The escape sequence "\\0" can be used in the pattern to |
| 37 |
represent a binary zero. |
represent a binary zero. |
| 38 |
|
|
| 39 |
4. The following Perl escape sequences are not supported: \\l, \\u, \\L, |
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 |
\\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 |
string-handling and are not part of its pattern matching engine. If any of |
| 42 |
these are encountered by PCRE, an error is generated. |
these are encountered by PCRE, an error is generated. |
| 43 |
|
|
| 44 |
5. PCRE does support the \\Q...\\E escape for quoting substrings. Characters in |
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 $ |
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 |
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 |
variable interpolation (but of course PCRE does not have variables). Note the |
| 54 |
\\Qabc\\$xyz\\E abc\\$xyz abc\\$xyz |
\\Qabc\\$xyz\\E abc\\$xyz abc\\$xyz |
| 55 |
\\Qabc\\E\\$\\Qxyz\\E abc$xyz abc$xyz |
\\Qabc\\E\\$\\Qxyz\\E abc$xyz abc$xyz |
| 56 |
|
|
| 57 |
In PCRE, the \\Q...\\E mechanism is not recognized inside a character class. |
The \\Q...\\E sequence is recognized both inside and outside character classes. |
| 58 |
|
|
| 59 |
8. Fairly obviously, PCRE does not support the (?{code}) and (?p{code}) |
7. Fairly obviously, PCRE does not support the (?{code}) and (?p{code}) |
| 60 |
constructions. However, there is some experimental support for recursive |
constructions. However, there is some experimental support for recursive |
| 61 |
patterns using the non-Perl items (?R), (?number) and (?P>name). Also, the PCRE |
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 |
"callout" feature allows an external function to be called during pattern |
| 63 |
matching. |
matching. |
| 64 |
|
|
| 65 |
9. There are some differences that are concerned with the settings of captured |
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 |
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". |
the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE it is set to "b". |
| 68 |
|
|
| 69 |
10. PCRE provides some extensions to the Perl regular expression facilities: |
9. PCRE provides some extensions to the Perl regular expression facilities: |
| 70 |
|
|
| 71 |
(a) Although lookbehind assertions must match fixed length strings, each |
(a) Although lookbehind assertions must match fixed length strings, each |
| 72 |
alternative branch of a lookbehind assertion can match a different length of |
alternative branch of a lookbehind assertion can match a different length of |
| 102 |
(k) The callout facility is PCRE-specific. |
(k) The callout facility is PCRE-specific. |
| 103 |
|
|
| 104 |
.in 0 |
.in 0 |
| 105 |
Last updated: 03 February 2003 |
Last updated: 09 December 2003 |
| 106 |
.br |
.br |
| 107 |
Copyright (c) 1997-2003 University of Cambridge. |
Copyright (c) 1997-2003 University of Cambridge. |