( ) |
Define Capturing Groups
Allows a group of characters to be treated as a single unit
Capturing Groups are numbered according to the number of opening
parentheses left to right.
|
[ ] |
Defines character class |
\n |
Back reference captured group n
Escape Character when used by itself \
|
| |
OR |
&& |
Intersection Operator |
. |
Any single character May or may not match line terminators |
, |
Bound number of matches |
Quantifiers |
? |
Match once or not at all
Also append to quantifier to create Reluctant Quantifier
|
* |
Match zero or more times |
+ |
Match one or more times
Also append to quantifier to create Possessive Quantifier
|
{n} |
Match pattern n times |
Boundary Matchers |
^ |
Match beginning of a line
Negation when used in character class
|
$ |
Match end of a line |
\b |
Word boundary |
\B |
Non-word boundary |
\A |
Beginning of input |
\G |
End of previous match |
\Z |
End of input but before final terminator, if any |
\z |
End of input |
Predefined Character Ranges |
\d |
A single digit [0-9] |
\D |
A single non-digit [^0-9] |
\s |
A single whitespace character [ \t\n\x0B\f\r] |
\S |
A single non-whitespace character [^\s] |
\w |
A single word character [a-zA-Z_0-9] |
\W |
A single non-word character [^\w] |
Embedded Flag Expressions |
(?i) |
Case Insensitive |
(?x) |
Comments - whitespace and # until end of line ignored |
(?m) |
Multi line |
(?s) |
Dot "." matches line terminators too |
(?u) |
Unicode |
(?d) |
Unix lines |
Precede meta character with backslash to have it be treated like
an ordinary character
Or enclose it within \Q and \E (start quote, end quote)
|