Structure |
The |
Character |
\\ |
Backslash character |
\ r |
Carriage return character (' \u000d ') |
\ n |
New lines (line break) (' \u000a ') |
Character class |
[ABC] |
a,b or c |
[^ABC] |
Any character except a,b , or C (negation) |
[A-za-z]
|
a to z or a to z, the letters at both ends are included (range) |
[A-d[m-p]] |
a to D or m to p:[a-dm-p](set) |
[A-z&&[def]] |
d,e or F(intersection) |
[A-Z&&[^BC]] |
a to Z, except for b and C:[ad-z](minus) |
[A-z&&[^m-p]] |
a to z, not m to p:[a-lq-z](minus) |
Predefined character classes |
. |
Any character (may or may not match the line terminator) |
\d |
Numbers:[0-9] |
\d |
Non-numeric: [^0-9] |
\s |
whitespace characters:[\t\n\x0b\f\r] |
\s |
Non-whitespace characters:[^\s] |
\w |
any word character that includes an underscore :[a-za-z0-9_] |
\w |
Non-word characters:[^\w] |
Boundary Matching Device |
^ |
The beginning of the line |
$ |
End of Line |
\b |
Word boundaries |
\b |
Non-word boundary |
\a |
Start of input |
\g |
End of last match |
\z |
The end of the input, only for the last terminator (if any) |
\z |
End of input |
Greedy number of words |
X? |
X, not once or once |
X* |
X, 0 or more times |
X+ |
X, one or more times |
X{n} |
X, exactly n times |
X{n,} |
X, at least n times |
X{n,m} |
X, at least n times, but not more than m times |
Reluctant number of words |
X ?? |
X, not once or once |
X *? |
X, 0 or more times |
X +? |
X, one or more times |
X {n}? |
X, exactly n times |
X {n,}? |
X, at least n times |
X {n,m}? |
X, at least n times, but not more than m Times |
possessive number of words |
X ?+ |
X, not once or once |
X *+ |
X, 0 or more times |
X ++ |
X, one or more times |
X {n}+ |
X, exactly n times |
X {n,}+ |
X, at least n times |
X {n,m}+ |
X, at least n times, but not more than m Times |
Logical operator |
XY |
X followed by Y |
X | Y |
X or Y |
(X) |
X, as capturing group |
Back reference |
\ N |
Any matching n-th capturing group |
References |
\ |
Nothing, but references the following characters |
\q |
Nothing, but all characters are quoted until \e |
\e |
Nothing, but the end of the reference starting from \q |