3 PCRE - Perl-compatible regular expressions
4 .SH "PCRE REGULAR EXPRESSION SYNTAX SUMMARY"
7 The full syntax and semantics of the regular expressions that are supported by
8 PCRE are described in the
12 documentation. This document contains just a quick-reference summary of the
19 \ex where x is non-alphanumeric is a literal x
20 \eQ...\eE treat enclosed characters as literal
26 \ea alarm, that is, the BEL character (hex 07)
27 \ecx "control-x", where x is any character
31 \er carriage return (hex 0D)
33 \eddd character with octal code ddd, or backreference
34 \exhh character with hex code hh
35 \ex{hhh..} character with hex code hhh..
41 . any character except newline;
42 in dotall mode, any character whatsoever
43 \eC one byte, even in UTF-8 mode (best avoided)
45 \eD a character that is not a decimal digit
46 \eh a horizontal whitespace character
47 \eH a character that is not a horizontal whitespace character
48 \ep{\fIxx\fP} a character with the \fIxx\fP property
49 \eP{\fIxx\fP} a character without the \fIxx\fP property
50 \eR a newline sequence
51 \es a whitespace character
52 \eS a character that is not a whitespace character
53 \ev a vertical whitespace character
54 \eV a character that is not a vertical whitespace character
55 \ew a "word" character
56 \eW a "non-word" character
57 \eX an extended Unicode sequence
59 In PCRE, \ed, \eD, \es, \eS, \ew, and \eW recognize only ASCII characters.
62 .SH "GENERAL CATEGORY PROPERTY CODES FOR \ep and \eP"
91 Pc Connector punctuation
95 Pi Initial punctuation
102 Sm Mathematical symbol
107 Zp Paragraph separator
111 .SH "SCRIPT NAMES FOR \ep AND \eP"
182 .SH "CHARACTER CLASSES"
185 [...] positive character class
186 [^...] negative character class
187 [x-y] range (can be used for hex characters)
188 [[:xxx:]] positive POSIX named set
189 [[:^xxx:]] negative POSIX named set
195 cntrl control character
197 graph printing, excluding space
198 lower lower case letter
199 print printing, including space
200 punct printing, excluding alphanumeric
202 upper upper case letter
204 xdigit hexadecimal digit
206 In PCRE, POSIX character set names recognize only ASCII characters. You can use
207 \eQ...\eE inside a character class.
214 ?+ 0 or 1, possessive
217 *+ 0 or more, possessive
220 ++ 1 or more, possessive
223 {n,m} at least n, no more than m, greedy
224 {n,m}+ at least n, no more than m, possessive
225 {n,m}? at least n, no more than m, lazy
226 {n,} n or more, greedy
227 {n,}+ n or more, possessive
228 {n,}? n or more, lazy
231 .SH "ANCHORS AND SIMPLE ASSERTIONS"
235 \eB not a word boundary
237 also after internal newline in multiline mode
240 also before newline at end of subject
241 also before internal newline in multiline mode
243 also before newline at end of subject
245 \eG first matching position in subject
248 .SH "MATCH POINT RESET"
251 \eK reset start of match
263 (...) capturing group
264 (?<name>...) named capturing group (Perl)
265 (?'name'...) named capturing group (Perl)
266 (?P<name>...) named capturing group (Python)
267 (?:...) non-capturing group
268 (?|...) non-capturing group; reset group numbers for
269 capturing groups in each alternative
275 (?>...) atomic, non-capturing group
283 (?#....) comment (not nestable)
290 (?J) allow duplicate names
292 (?s) single line (dotall)
293 (?U) default ungreedy (lazy)
294 (?x) extended (ignore white space)
295 (?-...) unset option(s)
298 .SH "LOOKAHEAD AND LOOKBEHIND ASSERTIONS"
301 (?=...) positive look ahead
302 (?!...) negative look ahead
303 (?<=...) positive look behind
304 (?<!...) negative look behind
306 Each top-level branch of a look behind must be of a fixed length.
310 \en reference by number (can be ambiguous)
311 \egn reference by number
312 \eg{n} reference by number
313 \eg{-n} relative reference by number
314 \ek<name> reference by name (Perl)
315 \ek'name' reference by name (Perl)
316 \eg{name} reference by name (Perl)
317 \ek{name} reference by name (.NET)
318 (?P=name) reference by name (Python)
321 .SH "SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)"
324 (?R) recurse whole pattern
325 (?n) call subpattern by absolute number
326 (?+n) call subpattern by relative number
327 (?-n) call subpattern by relative number
328 (?&name) call subpattern by name (Perl)
329 (?P>name) call subpattern by name (Python)
332 .SH "CONDITIONAL PATTERNS"
335 (?(condition)yes-pattern)
336 (?(condition)yes-pattern|no-pattern)
338 (?(n)... absolute reference condition
339 (?(+n)... relative reference condition
340 (?(-n)... relative reference condition
341 (?(<name>)... named reference condition (Perl)
342 (?('name')... named reference condition (Perl)
343 (?(name)... named reference condition (PCRE)
344 (?(R)... overall recursion condition
345 (?(Rn)... specific group recursion condition
346 (?(R&name)... specific recursion condition
347 (?(DEFINE)... define subpattern for reference
348 (?(assert)... assertion condition
351 .SH "BACKTRACKING CONTROL"
354 The following act immediately they are reached:
356 (*ACCEPT) force successful match
357 (*FAIL) force backtrack; synonym (*F)
359 The following act only when a subsequent match failure causes a backtrack to
360 reach them. They all force a match failure, but they differ in what happens
361 afterwards. Those that advance the start-of-match point do so only if the
362 pattern is not anchored.
364 (*COMMIT) overall failure, no advance of starting point
365 (*PRUNE) advance to next starting character
366 (*SKIP) advance start to current matching position
367 (*THEN) local failure, backtrack to next alternation
370 .SH "NEWLINE CONVENTIONS"
373 These are recognized only at the very start of the pattern or after a
383 .SH "WHAT \eR MATCHES"
386 These are recognized only at the very start of the pattern or after a
387 (*...) option that sets the newline convention.
397 (?Cn) callout with data n
403 \fBpcrepattern\fP(3), \fBpcreapi\fP(3), \fBpcrecallout\fP(3),
404 \fBpcrematching\fP(3), \fBpcre\fP(3).
412 University Computing Service
413 Cambridge CB2 3QH, England.
421 Last updated: 14 November 2007
422 Copyright (c) 1997-2007 University of Cambridge.