1 .TH PCRESYNTAX 3 "08 January 2014" "PCRE 8.35"
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 a quick-reference summary of the syntax.
18 \ex where x is non-alphanumeric is a literal x
19 \eQ...\eE treat enclosed characters as literal
25 \ea alarm, that is, the BEL character (hex 07)
26 \ecx "control-x", where x is any ASCII character
28 \ef form feed (hex 0C)
30 \er carriage return (hex 0D)
32 \e0dd character with octal code 0dd
33 \eddd character with octal code ddd, or backreference
34 \eo{ddd..} character with octal code ddd..
35 \exhh character with hex code hh
36 \ex{hhh..} character with hex code hhh..
38 Note that \e0dd is always an octal code, and that \e8 and \e9 are the literal
39 characters "8" and "9".
45 . any character except newline;
46 in dotall mode, any character whatsoever
47 \eC one data unit, even in UTF mode (best avoided)
49 \eD a character that is not a decimal digit
50 \eh a horizontal white space character
51 \eH a character that is not a horizontal white space character
52 \eN a character that is not a newline
53 \ep{\fIxx\fP} a character with the \fIxx\fP property
54 \eP{\fIxx\fP} a character without the \fIxx\fP property
55 \eR a newline sequence
56 \es a white space character
57 \eS a character that is not a white space character
58 \ev a vertical white space character
59 \eV a character that is not a vertical white space character
60 \ew a "word" character
61 \eW a "non-word" character
62 \eX a Unicode extended grapheme cluster
64 By default, \ed, \es, and \ew match only ASCII characters, even in UTF-8 mode
65 or in the 16- bit and 32-bit libraries. However, if locale-specific matching is
66 happening, \es and \ew may also match characters with code points in the range
67 128-255. If the PCRE_UCP option is set, the behaviour of these escape sequences
68 is changed to use Unicode properties and they match many more characters.
71 .SH "GENERAL CATEGORY PROPERTIES FOR \ep and \eP"
100 Pc Connector punctuation
104 Pi Initial punctuation
111 Sm Mathematical symbol
116 Zp Paragraph separator
120 .SH "PCRE SPECIAL CATEGORY PROPERTIES FOR \ep and \eP"
123 Xan Alphanumeric: union of properties L and N
124 Xps POSIX space: property Z or tab, NL, VT, FF, CR
125 Xsp Perl space: property Z or tab, NL, VT, FF, CR
126 Xuc Univerally-named character: one that can be
127 represented by a Universal Character Name
128 Xwd Perl word: property Xan or underscore
130 Perl and POSIX space are now the same. Perl added VT to its space character set
131 at release 5.18 and PCRE changed at release 8.34.
134 .SH "SCRIPT NAMES FOR \ep AND \eP"
161 Egyptian_Hieroglyphs,
176 Inscriptional_Pahlavi,
177 Inscriptional_Parthian,
197 Meroitic_Hieroglyphs,
241 .SH "CHARACTER CLASSES"
244 [...] positive character class
245 [^...] negative character class
246 [x-y] range (can be used for hex characters)
247 [[:xxx:]] positive POSIX named set
248 [[:^xxx:]] negative POSIX named set
254 cntrl control character
256 graph printing, excluding space
257 lower lower case letter
258 print printing, including space
259 punct printing, excluding alphanumeric
261 upper upper case letter
263 xdigit hexadecimal digit
265 In PCRE, POSIX character set names recognize only ASCII characters by default,
266 but some of them use Unicode properties if PCRE_UCP is set. You can use
267 \eQ...\eE inside a character class.
274 ?+ 0 or 1, possessive
277 *+ 0 or more, possessive
280 ++ 1 or more, possessive
283 {n,m} at least n, no more than m, greedy
284 {n,m}+ at least n, no more than m, possessive
285 {n,m}? at least n, no more than m, lazy
286 {n,} n or more, greedy
287 {n,}+ n or more, possessive
288 {n,}? n or more, lazy
291 .SH "ANCHORS AND SIMPLE ASSERTIONS"
295 \eB not a word boundary
297 also after internal newline in multiline mode
300 also before newline at end of subject
301 also before internal newline in multiline mode
303 also before newline at end of subject
305 \eG first matching position in subject
308 .SH "MATCH POINT RESET"
311 \eK reset start of match
313 \eK is honoured in positive assertions, but ignored in negative ones.
325 (...) capturing group
326 (?<name>...) named capturing group (Perl)
327 (?'name'...) named capturing group (Perl)
328 (?P<name>...) named capturing group (Python)
329 (?:...) non-capturing group
330 (?|...) non-capturing group; reset group numbers for
331 capturing groups in each alternative
337 (?>...) atomic, non-capturing group
345 (?#....) comment (not nestable)
352 (?J) allow duplicate names
354 (?s) single line (dotall)
355 (?U) default ungreedy (lazy)
356 (?x) extended (ignore white space)
357 (?-...) unset option(s)
359 The following are recognized only at the very start of a pattern or after one
360 of the newline or \eR options with similar syntax. More than one of them may
363 (*LIMIT_MATCH=d) set the match limit to d (decimal number)
364 (*LIMIT_RECURSION=d) set the recursion limit to d (decimal number)
365 (*NO_AUTO_POSSESS) no auto-possessification (PCRE_NO_AUTO_POSSESS)
366 (*NO_START_OPT) no start-match optimization (PCRE_NO_START_OPTIMIZE)
367 (*UTF8) set UTF-8 mode: 8-bit library (PCRE_UTF8)
368 (*UTF16) set UTF-16 mode: 16-bit library (PCRE_UTF16)
369 (*UTF32) set UTF-32 mode: 32-bit library (PCRE_UTF32)
370 (*UTF) set appropriate UTF mode for the library in use
371 (*UCP) set PCRE_UCP (use Unicode properties for \ed etc)
373 Note that LIMIT_MATCH and LIMIT_RECURSION can only reduce the value of the
374 limits set by the caller of pcre_exec(), not increase them.
377 .SH "NEWLINE CONVENTION"
380 These are recognized only at the very start of the pattern or after option
381 settings with a similar syntax.
383 (*CR) carriage return only
385 (*CRLF) carriage return followed by linefeed
386 (*ANYCRLF) all three of the above
387 (*ANY) any Unicode newline sequence
390 .SH "WHAT \eR MATCHES"
393 These are recognized only at the very start of the pattern or after option
394 setting with a similar syntax.
396 (*BSR_ANYCRLF) CR, LF, or CRLF
397 (*BSR_UNICODE) any Unicode newline sequence
400 .SH "LOOKAHEAD AND LOOKBEHIND ASSERTIONS"
403 (?=...) positive look ahead
404 (?!...) negative look ahead
405 (?<=...) positive look behind
406 (?<!...) negative look behind
408 Each top-level branch of a look behind must be of a fixed length.
414 \en reference by number (can be ambiguous)
415 \egn reference by number
416 \eg{n} reference by number
417 \eg{-n} relative reference by number
418 \ek<name> reference by name (Perl)
419 \ek'name' reference by name (Perl)
420 \eg{name} reference by name (Perl)
421 \ek{name} reference by name (.NET)
422 (?P=name) reference by name (Python)
425 .SH "SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)"
428 (?R) recurse whole pattern
429 (?n) call subpattern by absolute number
430 (?+n) call subpattern by relative number
431 (?-n) call subpattern by relative number
432 (?&name) call subpattern by name (Perl)
433 (?P>name) call subpattern by name (Python)
434 \eg<name> call subpattern by name (Oniguruma)
435 \eg'name' call subpattern by name (Oniguruma)
436 \eg<n> call subpattern by absolute number (Oniguruma)
437 \eg'n' call subpattern by absolute number (Oniguruma)
438 \eg<+n> call subpattern by relative number (PCRE extension)
439 \eg'+n' call subpattern by relative number (PCRE extension)
440 \eg<-n> call subpattern by relative number (PCRE extension)
441 \eg'-n' call subpattern by relative number (PCRE extension)
444 .SH "CONDITIONAL PATTERNS"
447 (?(condition)yes-pattern)
448 (?(condition)yes-pattern|no-pattern)
450 (?(n)... absolute reference condition
451 (?(+n)... relative reference condition
452 (?(-n)... relative reference condition
453 (?(<name>)... named reference condition (Perl)
454 (?('name')... named reference condition (Perl)
455 (?(name)... named reference condition (PCRE)
456 (?(R)... overall recursion condition
457 (?(Rn)... specific group recursion condition
458 (?(R&name)... specific recursion condition
459 (?(DEFINE)... define subpattern for reference
460 (?(assert)... assertion condition
463 .SH "BACKTRACKING CONTROL"
466 The following act immediately they are reached:
468 (*ACCEPT) force successful match
469 (*FAIL) force backtrack; synonym (*F)
470 (*MARK:NAME) set name to be passed back; synonym (*:NAME)
472 The following act only when a subsequent match failure causes a backtrack to
473 reach them. They all force a match failure, but they differ in what happens
474 afterwards. Those that advance the start-of-match point do so only if the
475 pattern is not anchored.
477 (*COMMIT) overall failure, no advance of starting point
478 (*PRUNE) advance to next starting character
479 (*PRUNE:NAME) equivalent to (*MARK:NAME)(*PRUNE)
480 (*SKIP) advance to current matching position
481 (*SKIP:NAME) advance to position corresponding to an earlier
482 (*MARK:NAME); if not found, the (*SKIP) is ignored
483 (*THEN) local failure, backtrack to next alternation
484 (*THEN:NAME) equivalent to (*MARK:NAME)(*THEN)
491 (?Cn) callout with data n
497 \fBpcrepattern\fP(3), \fBpcreapi\fP(3), \fBpcrecallout\fP(3),
498 \fBpcrematching\fP(3), \fBpcre\fP(3).
506 University Computing Service
507 Cambridge CB2 3QH, England.
515 Last updated: 08 January 2014
516 Copyright (c) 1997-2014 University of Cambridge.