1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tools/pcre/doc/pcresyntax.3 Tue Jul 28 17:51:34 2009 -0400
1.3 @@ -0,0 +1,449 @@
1.4 +.TH PCRESYNTAX 3
1.5 +.SH NAME
1.6 +PCRE - Perl-compatible regular expressions
1.7 +.SH "PCRE REGULAR EXPRESSION SYNTAX SUMMARY"
1.8 +.rs
1.9 +.sp
1.10 +The full syntax and semantics of the regular expressions that are supported by
1.11 +PCRE are described in the
1.12 +.\" HREF
1.13 +\fBpcrepattern\fP
1.14 +.\"
1.15 +documentation. This document contains just a quick-reference summary of the
1.16 +syntax.
1.17 +.
1.18 +.
1.19 +.SH "QUOTING"
1.20 +.rs
1.21 +.sp
1.22 + \ex where x is non-alphanumeric is a literal x
1.23 + \eQ...\eE treat enclosed characters as literal
1.24 +.
1.25 +.
1.26 +.SH "CHARACTERS"
1.27 +.rs
1.28 +.sp
1.29 + \ea alarm, that is, the BEL character (hex 07)
1.30 + \ecx "control-x", where x is any character
1.31 + \ee escape (hex 1B)
1.32 + \ef formfeed (hex 0C)
1.33 + \en newline (hex 0A)
1.34 + \er carriage return (hex 0D)
1.35 + \et tab (hex 09)
1.36 + \eddd character with octal code ddd, or backreference
1.37 + \exhh character with hex code hh
1.38 + \ex{hhh..} character with hex code hhh..
1.39 +.
1.40 +.
1.41 +.SH "CHARACTER TYPES"
1.42 +.rs
1.43 +.sp
1.44 + . any character except newline;
1.45 + in dotall mode, any character whatsoever
1.46 + \eC one byte, even in UTF-8 mode (best avoided)
1.47 + \ed a decimal digit
1.48 + \eD a character that is not a decimal digit
1.49 + \eh a horizontal whitespace character
1.50 + \eH a character that is not a horizontal whitespace character
1.51 + \ep{\fIxx\fP} a character with the \fIxx\fP property
1.52 + \eP{\fIxx\fP} a character without the \fIxx\fP property
1.53 + \eR a newline sequence
1.54 + \es a whitespace character
1.55 + \eS a character that is not a whitespace character
1.56 + \ev a vertical whitespace character
1.57 + \eV a character that is not a vertical whitespace character
1.58 + \ew a "word" character
1.59 + \eW a "non-word" character
1.60 + \eX an extended Unicode sequence
1.61 +.sp
1.62 +In PCRE, \ed, \eD, \es, \eS, \ew, and \eW recognize only ASCII characters.
1.63 +.
1.64 +.
1.65 +.SH "GENERAL CATEGORY PROPERTY CODES FOR \ep and \eP"
1.66 +.rs
1.67 +.sp
1.68 + C Other
1.69 + Cc Control
1.70 + Cf Format
1.71 + Cn Unassigned
1.72 + Co Private use
1.73 + Cs Surrogate
1.74 +.sp
1.75 + L Letter
1.76 + Ll Lower case letter
1.77 + Lm Modifier letter
1.78 + Lo Other letter
1.79 + Lt Title case letter
1.80 + Lu Upper case letter
1.81 + L& Ll, Lu, or Lt
1.82 +.sp
1.83 + M Mark
1.84 + Mc Spacing mark
1.85 + Me Enclosing mark
1.86 + Mn Non-spacing mark
1.87 +.sp
1.88 + N Number
1.89 + Nd Decimal number
1.90 + Nl Letter number
1.91 + No Other number
1.92 +.sp
1.93 + P Punctuation
1.94 + Pc Connector punctuation
1.95 + Pd Dash punctuation
1.96 + Pe Close punctuation
1.97 + Pf Final punctuation
1.98 + Pi Initial punctuation
1.99 + Po Other punctuation
1.100 + Ps Open punctuation
1.101 +.sp
1.102 + S Symbol
1.103 + Sc Currency symbol
1.104 + Sk Modifier symbol
1.105 + Sm Mathematical symbol
1.106 + So Other symbol
1.107 +.sp
1.108 + Z Separator
1.109 + Zl Line separator
1.110 + Zp Paragraph separator
1.111 + Zs Space separator
1.112 +.
1.113 +.
1.114 +.SH "SCRIPT NAMES FOR \ep AND \eP"
1.115 +.rs
1.116 +.sp
1.117 +Arabic,
1.118 +Armenian,
1.119 +Balinese,
1.120 +Bengali,
1.121 +Bopomofo,
1.122 +Braille,
1.123 +Buginese,
1.124 +Buhid,
1.125 +Canadian_Aboriginal,
1.126 +Carian,
1.127 +Cham,
1.128 +Cherokee,
1.129 +Common,
1.130 +Coptic,
1.131 +Cuneiform,
1.132 +Cypriot,
1.133 +Cyrillic,
1.134 +Deseret,
1.135 +Devanagari,
1.136 +Ethiopic,
1.137 +Georgian,
1.138 +Glagolitic,
1.139 +Gothic,
1.140 +Greek,
1.141 +Gujarati,
1.142 +Gurmukhi,
1.143 +Han,
1.144 +Hangul,
1.145 +Hanunoo,
1.146 +Hebrew,
1.147 +Hiragana,
1.148 +Inherited,
1.149 +Kannada,
1.150 +Katakana,
1.151 +Kayah_Li,
1.152 +Kharoshthi,
1.153 +Khmer,
1.154 +Lao,
1.155 +Latin,
1.156 +Lepcha,
1.157 +Limbu,
1.158 +Linear_B,
1.159 +Lycian,
1.160 +Lydian,
1.161 +Malayalam,
1.162 +Mongolian,
1.163 +Myanmar,
1.164 +New_Tai_Lue,
1.165 +Nko,
1.166 +Ogham,
1.167 +Old_Italic,
1.168 +Old_Persian,
1.169 +Ol_Chiki,
1.170 +Oriya,
1.171 +Osmanya,
1.172 +Phags_Pa,
1.173 +Phoenician,
1.174 +Rejang,
1.175 +Runic,
1.176 +Saurashtra,
1.177 +Shavian,
1.178 +Sinhala,
1.179 +Sudanese,
1.180 +Syloti_Nagri,
1.181 +Syriac,
1.182 +Tagalog,
1.183 +Tagbanwa,
1.184 +Tai_Le,
1.185 +Tamil,
1.186 +Telugu,
1.187 +Thaana,
1.188 +Thai,
1.189 +Tibetan,
1.190 +Tifinagh,
1.191 +Ugaritic,
1.192 +Vai,
1.193 +Yi.
1.194 +.
1.195 +.
1.196 +.SH "CHARACTER CLASSES"
1.197 +.rs
1.198 +.sp
1.199 + [...] positive character class
1.200 + [^...] negative character class
1.201 + [x-y] range (can be used for hex characters)
1.202 + [[:xxx:]] positive POSIX named set
1.203 + [[:^xxx:]] negative POSIX named set
1.204 +.sp
1.205 + alnum alphanumeric
1.206 + alpha alphabetic
1.207 + ascii 0-127
1.208 + blank space or tab
1.209 + cntrl control character
1.210 + digit decimal digit
1.211 + graph printing, excluding space
1.212 + lower lower case letter
1.213 + print printing, including space
1.214 + punct printing, excluding alphanumeric
1.215 + space whitespace
1.216 + upper upper case letter
1.217 + word same as \ew
1.218 + xdigit hexadecimal digit
1.219 +.sp
1.220 +In PCRE, POSIX character set names recognize only ASCII characters. You can use
1.221 +\eQ...\eE inside a character class.
1.222 +.
1.223 +.
1.224 +.SH "QUANTIFIERS"
1.225 +.rs
1.226 +.sp
1.227 + ? 0 or 1, greedy
1.228 + ?+ 0 or 1, possessive
1.229 + ?? 0 or 1, lazy
1.230 + * 0 or more, greedy
1.231 + *+ 0 or more, possessive
1.232 + *? 0 or more, lazy
1.233 + + 1 or more, greedy
1.234 + ++ 1 or more, possessive
1.235 + +? 1 or more, lazy
1.236 + {n} exactly n
1.237 + {n,m} at least n, no more than m, greedy
1.238 + {n,m}+ at least n, no more than m, possessive
1.239 + {n,m}? at least n, no more than m, lazy
1.240 + {n,} n or more, greedy
1.241 + {n,}+ n or more, possessive
1.242 + {n,}? n or more, lazy
1.243 +.
1.244 +.
1.245 +.SH "ANCHORS AND SIMPLE ASSERTIONS"
1.246 +.rs
1.247 +.sp
1.248 + \eb word boundary (only ASCII letters recognized)
1.249 + \eB not a word boundary
1.250 + ^ start of subject
1.251 + also after internal newline in multiline mode
1.252 + \eA start of subject
1.253 + $ end of subject
1.254 + also before newline at end of subject
1.255 + also before internal newline in multiline mode
1.256 + \eZ end of subject
1.257 + also before newline at end of subject
1.258 + \ez end of subject
1.259 + \eG first matching position in subject
1.260 +.
1.261 +.
1.262 +.SH "MATCH POINT RESET"
1.263 +.rs
1.264 +.sp
1.265 + \eK reset start of match
1.266 +.
1.267 +.
1.268 +.SH "ALTERNATION"
1.269 +.rs
1.270 +.sp
1.271 + expr|expr|expr...
1.272 +.
1.273 +.
1.274 +.SH "CAPTURING"
1.275 +.rs
1.276 +.sp
1.277 + (...) capturing group
1.278 + (?<name>...) named capturing group (Perl)
1.279 + (?'name'...) named capturing group (Perl)
1.280 + (?P<name>...) named capturing group (Python)
1.281 + (?:...) non-capturing group
1.282 + (?|...) non-capturing group; reset group numbers for
1.283 + capturing groups in each alternative
1.284 +.
1.285 +.
1.286 +.SH "ATOMIC GROUPS"
1.287 +.rs
1.288 +.sp
1.289 + (?>...) atomic, non-capturing group
1.290 +.
1.291 +.
1.292 +.
1.293 +.
1.294 +.SH "COMMENT"
1.295 +.rs
1.296 +.sp
1.297 + (?#....) comment (not nestable)
1.298 +.
1.299 +.
1.300 +.SH "OPTION SETTING"
1.301 +.rs
1.302 +.sp
1.303 + (?i) caseless
1.304 + (?J) allow duplicate names
1.305 + (?m) multiline
1.306 + (?s) single line (dotall)
1.307 + (?U) default ungreedy (lazy)
1.308 + (?x) extended (ignore white space)
1.309 + (?-...) unset option(s)
1.310 +.sp
1.311 +The following is recognized only at the start of a pattern or after one of the
1.312 +newline-setting options with similar syntax:
1.313 +.sp
1.314 + (*UTF8) set UTF-8 mode
1.315 +.
1.316 +.
1.317 +.SH "LOOKAHEAD AND LOOKBEHIND ASSERTIONS"
1.318 +.rs
1.319 +.sp
1.320 + (?=...) positive look ahead
1.321 + (?!...) negative look ahead
1.322 + (?<=...) positive look behind
1.323 + (?<!...) negative look behind
1.324 +.sp
1.325 +Each top-level branch of a look behind must be of a fixed length.
1.326 +.
1.327 +.
1.328 +.SH "BACKREFERENCES"
1.329 +.rs
1.330 +.sp
1.331 + \en reference by number (can be ambiguous)
1.332 + \egn reference by number
1.333 + \eg{n} reference by number
1.334 + \eg{-n} relative reference by number
1.335 + \ek<name> reference by name (Perl)
1.336 + \ek'name' reference by name (Perl)
1.337 + \eg{name} reference by name (Perl)
1.338 + \ek{name} reference by name (.NET)
1.339 + (?P=name) reference by name (Python)
1.340 +.
1.341 +.
1.342 +.SH "SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)"
1.343 +.rs
1.344 +.sp
1.345 + (?R) recurse whole pattern
1.346 + (?n) call subpattern by absolute number
1.347 + (?+n) call subpattern by relative number
1.348 + (?-n) call subpattern by relative number
1.349 + (?&name) call subpattern by name (Perl)
1.350 + (?P>name) call subpattern by name (Python)
1.351 + \eg<name> call subpattern by name (Oniguruma)
1.352 + \eg'name' call subpattern by name (Oniguruma)
1.353 + \eg<n> call subpattern by absolute number (Oniguruma)
1.354 + \eg'n' call subpattern by absolute number (Oniguruma)
1.355 + \eg<+n> call subpattern by relative number (PCRE extension)
1.356 + \eg'+n' call subpattern by relative number (PCRE extension)
1.357 + \eg<-n> call subpattern by relative number (PCRE extension)
1.358 + \eg'-n' call subpattern by relative number (PCRE extension)
1.359 +.
1.360 +.
1.361 +.SH "CONDITIONAL PATTERNS"
1.362 +.rs
1.363 +.sp
1.364 + (?(condition)yes-pattern)
1.365 + (?(condition)yes-pattern|no-pattern)
1.366 +.sp
1.367 + (?(n)... absolute reference condition
1.368 + (?(+n)... relative reference condition
1.369 + (?(-n)... relative reference condition
1.370 + (?(<name>)... named reference condition (Perl)
1.371 + (?('name')... named reference condition (Perl)
1.372 + (?(name)... named reference condition (PCRE)
1.373 + (?(R)... overall recursion condition
1.374 + (?(Rn)... specific group recursion condition
1.375 + (?(R&name)... specific recursion condition
1.376 + (?(DEFINE)... define subpattern for reference
1.377 + (?(assert)... assertion condition
1.378 +.
1.379 +.
1.380 +.SH "BACKTRACKING CONTROL"
1.381 +.rs
1.382 +.sp
1.383 +The following act immediately they are reached:
1.384 +.sp
1.385 + (*ACCEPT) force successful match
1.386 + (*FAIL) force backtrack; synonym (*F)
1.387 +.sp
1.388 +The following act only when a subsequent match failure causes a backtrack to
1.389 +reach them. They all force a match failure, but they differ in what happens
1.390 +afterwards. Those that advance the start-of-match point do so only if the
1.391 +pattern is not anchored.
1.392 +.sp
1.393 + (*COMMIT) overall failure, no advance of starting point
1.394 + (*PRUNE) advance to next starting character
1.395 + (*SKIP) advance start to current matching position
1.396 + (*THEN) local failure, backtrack to next alternation
1.397 +.
1.398 +.
1.399 +.SH "NEWLINE CONVENTIONS"
1.400 +.rs
1.401 +.sp
1.402 +These are recognized only at the very start of the pattern or after a
1.403 +(*BSR_...) or (*UTF8) option.
1.404 +.sp
1.405 + (*CR) carriage return only
1.406 + (*LF) linefeed only
1.407 + (*CRLF) carriage return followed by linefeed
1.408 + (*ANYCRLF) all three of the above
1.409 + (*ANY) any Unicode newline sequence
1.410 +.
1.411 +.
1.412 +.SH "WHAT \eR MATCHES"
1.413 +.rs
1.414 +.sp
1.415 +These are recognized only at the very start of the pattern or after a
1.416 +(*...) option that sets the newline convention or UTF-8 mode.
1.417 +.sp
1.418 + (*BSR_ANYCRLF) CR, LF, or CRLF
1.419 + (*BSR_UNICODE) any Unicode newline sequence
1.420 +.
1.421 +.
1.422 +.SH "CALLOUTS"
1.423 +.rs
1.424 +.sp
1.425 + (?C) callout
1.426 + (?Cn) callout with data n
1.427 +.
1.428 +.
1.429 +.SH "SEE ALSO"
1.430 +.rs
1.431 +.sp
1.432 +\fBpcrepattern\fP(3), \fBpcreapi\fP(3), \fBpcrecallout\fP(3),
1.433 +\fBpcrematching\fP(3), \fBpcre\fP(3).
1.434 +.
1.435 +.
1.436 +.SH AUTHOR
1.437 +.rs
1.438 +.sp
1.439 +.nf
1.440 +Philip Hazel
1.441 +University Computing Service
1.442 +Cambridge CB2 3QH, England.
1.443 +.fi
1.444 +.
1.445 +.
1.446 +.SH REVISION
1.447 +.rs
1.448 +.sp
1.449 +.nf
1.450 +Last updated: 11 April 2009
1.451 +Copyright (c) 1997-2009 University of Cambridge.
1.452 +.fi