Regex Cheatsheet
A quick reference for common Regular Expression patterns and syntax.
Anchors
Pattern | Description |
---|---|
^ |
Matches the beginning of the string. |
$ |
Matches the end of the string. |
\b |
Matches a word boundary. |
\B |
Matches a non-word boundary. |
Character Classes
Pattern | Description |
---|---|
. |
Matches any single character except newline. |
\d |
Matches any digit (0-9). |
\D |
Matches any non-digit. |
\w |
Matches any word character (alphanumeric & underscore). |
\W |
Matches any non-word character. |
\s |
Matches any whitespace character (space, tab, newline). |
\S |
Matches any non-whitespace character. |
[abc] |
Matches any character in the set (a, b, or c). |
[^abc] |
Matches any character not in the set. |
[a-z] |
Matches any character in the range a to z. |
Flags / Modifiers
Pattern | Description |
---|---|
g |
Global search (don't return after the first match). |
i |
Case-insensitive search. |
m |
Multi-line search. |
Grouping and Capturing
Pattern | Description |
---|---|
(...) |
Captures the matched group. |
(?:...) |
Non-capturing group. |
| |
Acts like a boolean OR. Matches the expression before or after the |. |
Quantifiers
Pattern | Description |
---|---|
* |
Matches 0 or more repetitions of the preceding character. |
+ |
Matches 1 or more repetitions of the preceding character. |
? |
Matches 0 or 1 repetition of the preceding character. |
{n} |
Matches exactly n repetitions. |
{n,} |
Matches n or more repetitions. |
{n,m} |
Matches between n and m repetitions. |