Skip to main content
Very useful regular expression quick reference
flags
g - global match
i - ignore case
m - match over multiple lines
Escaping
\ - special characters to literal and literal characters to special
Quantifiers
? - matches zero or one times
* - matches zero or more times
+ - matches one or more times
{n} - matches n times
{n, m} - matches at least n times, but not more than m times
Anchors
^ - matches at the start of the line
$ - matches at the end of the line
\b - matches at the beginning or the end of a word
delimiter
(?:x) - matches x not remember the match
x(?=y) - matches x only if x is followed by y
x(?!y) - matches x only if x is not followed by y
Character Escapes
\s - matches whitespace
\S - matches anything but a whitespace
\f - matches a form-feed
\n - matches a linefeed
\r - matches a carriage return
\t - matches a horizontal tab
\v - matches vertical tab
\w - matches any alphanumeric character including the underscore. Equivalent to [A-Za-z0-9_]
\W - matches any non-word character. Equivalent to [^A-Za-z0-9_]
Others
. - matches any character except a newline
Comments
Post a Comment