Regex Cheatsheet
Anchors
^ | Start of string/line |
$ | End of string/line |
\b | Word boundary |
\B | Non-boundary |
Character classes
[abc] | Any of a, b, c |
[^abc] | Anything but a, b, c |
[a-z] | Range lowercase a–z |
[0-9] | Digit 0–9 |
. | Any except newline |
Predefined classes
\d | Digit (0-9) |
\D | Non-digit |
\w | Word char [A-Za-z0-9_] |
\W | Non-word |
\s | Whitespace |
\S | Non-whitespace |
Quantifiers
* | 0 or more |
+ | 1 or more |
? | 0 or 1 (optional) |
{n} | Exactly n |
{n,} | n or more |
{n,m} | Between n and m |
?? *? +? | Lazy quantifiers |
Groups & references
(abc) | Capturing group |
(?:abc) | Non-capturing group |
(?<name>abc) | Named group |
\1, \2 | Backreference to group 1, 2 |
\k<name> | Named backreference |
Lookaround
(?=abc) | Positive lookahead |
(?!abc) | Negative lookahead |
(?<=abc) | Positive lookbehind |
(?<!abc) | Negative lookbehind |
Alternation
a|b | Match a OR b |
Escapes
\\ | Literal backslash |
\. | Literal period |
\n | Newline |
\t | Tab |
\xFF | Hex char |
\u00FF | Unicode char |
Flags (JS)
g | Global — all matches |
i | Case-insensitive |
m | Multiline (^ and $ per line) |
s | Dotall (. matches newline) |
u | Unicode |
y | Sticky |
About this tool
Regex Cheatsheet is a single-purpose utility on instant.tw, a free toolbox of calculators, converters, generators, and quick lookups. Everything works in your browser — nothing is uploaded, nothing is stored on a server unless explicitly noted.
Category: Developer Tools — Advanced. Browse more Developer Tools — Advanced tools.