Flags:
| g |
Perform a global match |
| i |
Perform case-insensitive matching |
| m |
Treat beginning and end characters (^ and $) as working over multiple lines |
| u |
Treat the pattern as a series of Unicode code points
(
See the MDN docs
)
|
| y |
Sticky; treat the pattern after a match as a separate pattern |
Brackets:
[abc]
Match a single character a, b, or c
[^abc]
Match any character except a, b, or c
[A-Za-z]
Match any character from uppercase A to lowercase z
(ab|cd|ef)
Match either ab, cd, or ef
(...)
Capture anything enclosed
Metacharacters
^
Start of line
$
End of line
.
Match any character
\w
Match a word chracter
\W
Match a non-word character
\d
Match a digit
\D
Match any non-digit character
\s
Match a whitespace character
\S
Match a non-whitespace character
\b
Match character at the beginning or end of a word
\B
Match a character not at beginning or end of a word
0円
Match a NUL character
\t
Match a tab character
\xxx
Match a character specified by octal number xxx
\xdd
Match a character specified by hexadecimal number dd
\uxxxx
Match a Unicode character specified by hexadecimal number xxxx
Quantifiers
n+
Match at least one n
n*
Match zero or more n's
n?
Match zero or one n
n{X}
Match sequence of X n's
n{X,Y}
Match sequence of X to Y n's
n{X,}
Match sequence of X or more n's