Metacharacters
Metacharacters express sets of characters or special characters.
\
quotes special characters (* ? + [ ] ( ) { } ^ $ | \ . / )
\s
white space character (\t \n \f \r \p{Z})
[…]
match any character (or range of characters) inside the brackets. Range may be e.g. [a-z], [A-Z], [3…5], etc.
\D
any character that is not a decimal digit
\S
non-white space character
Operators
Operators allow to describe how an expression (or subexpression) should
be matched.
(…)
groups expression into subexpressions
A|B
alternation. Matches A or B
?
match zero or one times
{n}
match exactly n times
{n,m}
match at least n time and not more than m
Non-capturing operators
These operators work by one simple rule. They are not captured in groups.
(?:…)
Subexpression must occur but it's not captured in group.
(?!…)
Makes sure that the subexpression does not occur at current position. It's useful to exclude part of expression.