This is a static reference page — nothing you do here is sent anywhere. The 'Try it' links open the Regex Tester, which also runs entirely in your browser.
Read the full privacy policy →Regex Cheat Sheet
A complete regex syntax reference — character classes, anchors, quantifiers, groups, lookaround, and flags. Click Try it on any row to open it live in the Regex Tester.
Character Classes
Match a single character from a category or a custom set.
| Syntax | Matches | |
|---|---|---|
| . | Any character except a newline. | Try it → |
| \d | Any digit (0-9). | Try it → |
| \D | Any non-digit character. | Try it → |
| \w | Any word character: letters, digits, or underscore. | Try it → |
| \W | Any non-word character. | Try it → |
| \s | Any whitespace: space, tab, or newline. | Try it → |
| \S | Any non-whitespace character. | Try it → |
| [abc] | Any one character from the set — here, a, b, or c. | Try it → |
| [^abc] | Any character NOT in the set. | Try it → |
| [a-z] | Any character in the range a to z. | Try it → |
Anchors
Match a position in the text rather than a character.
Quantifiers
Control how many times the preceding token can repeat.
| Syntax | Matches | |
|---|---|---|
| * | 0 or more of the preceding token. | Try it → |
| + | 1 or more of the preceding token. | Try it → |
| ? | 0 or 1 of the preceding token (makes it optional). | Try it → |
| {n} | Exactly n times. | Try it → |
| {n,} | n or more times. | Try it → |
| {n,m} | Between n and m times, inclusive. | Try it → |
| *? +? ?? | Lazy (non-greedy) versions of *, +, and ? — match as few characters as possible instead of as many. | Try it → |
Groups & Alternation
Group parts of a pattern together, or match one of several options.
| Syntax | Matches | |
|---|---|---|
| (...) | Capturing group — remembers the text it matched so you can extract it. | Try it → |
| (?:...) | Non-capturing group — groups a pattern without remembering the matched text. | Try it → |
| (?<name>...) | Named capturing group — like (...), but accessible by name instead of position. | Try it → |
| | | Alternation — matches whatever is on either side of it (like OR). | Try it → |
| \1 | Backreference — matches the exact same text that capturing group 1 already matched. | Try it → |
Lookaround
Zero-width assertions — check what's nearby without including it in the match.
| Syntax | Matches | |
|---|---|---|
| (?=...) | Positive lookahead — matches only if followed by the pattern, without consuming it. | Try it → |
| (?!...) | Negative lookahead — matches only if NOT followed by the pattern. | Try it → |
| (?<=...) | Positive lookbehind — matches only if preceded by the pattern. | Try it → |
| (?<!...) | Negative lookbehind — matches only if NOT preceded by the pattern. | Try it → |
Flags
Modifiers placed after the closing slash of a regex (e.g. /pattern/gi) that change how it matches.
| Syntax | Matches | |
|---|---|---|
| g | Global — find all matches instead of stopping at the first one. | |
| i | Case-insensitive — ignore uppercase/lowercase differences. | |
| m | Multiline — makes ^ and $ match the start/end of each line, not just the whole string. | |
| s | Dot matches newline — makes . also match line break characters. | |
| u | Unicode mode — treats the pattern as full Unicode code points. | |
| y | Sticky — matches only starting at the exact lastIndex position, without scanning ahead. |
Escaping Special Characters
These characters are special to regex — prefix any of them with a backslash to match them literally: . * + ? ^ $ { } ( ) | [ ] \
| Syntax | Matches | |
|---|---|---|
| \. | Escapes a special character so it matches literally — here, a literal dot. | Try it → |