Regex Cheatsheet
Character Classes
. | Any char except newline |
\w | Word char [a-zA-Z0-9_] |
\d | Digit [0-9] |
\s | Whitespace |
\W\D\S | Inverse of above |
[abc] | Any of a, b, c |
[^abc] | Not a, b, c |
[a-z] | Range a to z |
Quantifiers
* | 0 or more |
+ | 1 or more |
? | 0 or 1 |
{n} | Exactly n |
{n,} | n or more |
{n,m} | Between n and m |
*?+? | Lazy (non-greedy) |
Anchors & Boundaries
^ | Start of string/line |
$ | End of string/line |
\b | Word boundary |
\B | Not word boundary |
Groups & Lookaheads
(abc) | Capture group |
(?:abc) | Non-capture group |
(?<n>abc) | Named group |
a(?=b) | Positive lookahead |
a(?!b) | Negative lookahead |
(?<=a)b | Positive lookbehind |
a|b | Alternation (a or b) |