文档介绍:Anchors Quantifiers Groups and Ranges
^ Start of string * 0 or more . Any character except
\A Start of string + 1 or more new line (\n)
$ End of string ? 0 or 1 (a|b) a or b
\Z End of string {3} Exactly 3 (...) Group
\b Word boundary {3,} 3 or more (?:...) Passive Group
\B Not word boundary {3,5} 3, 4 or 5 [abc] Range (a or b or c)
\< Start of word [^abc] Not a or b or c
\> End of word [a-q] Letter between a and q
Quantifier Modifiers
[A-Q] Upper case letter
between A and Q
Character Classes "x" below represents a quantifier
[0-7]
x? Ungreedy version of "x" Digit between 0 and 7
\n nth group/subpattern
\c Control character
Note: Ranges are inclusive.
\s White space Escape Character
\S Not white space
Pattern Modifiers
\d Digit \ Escape Character
\D Not digit
g
\w Word Global match
i
\W Not word Metacharacters (must be escaped) Case-insensitive
m
\x Hexadecimal digit Multiple lines
^ [ . s
\O Octal digit Treat string as single line
$ { * x ments and
( \ + white space in pattern
POSIX
) | ? e Evaluate replacement
< > U Ungreedy pattern
[:upper:] Upper case letters
[:lower:] Lower case letters
[:alpha:] All letters Special Characters String Replacement (Backreferences)
[:alnum:] Digits and letters
[:digit:] Digits \n New line $n nth non-passive group
[:xdigit:] Hexadecimal digits \r Carriage return $2