Regex Cheat Sheet & Builder
Regular expressions reference: anchors, classes, quantifiers, groups and flags with examples, plus ready recipes (email, URL, IP) and a live tester with highlighting.
Flags
Matches: 2
Contact me at user@example.com or admin@test.org!
Common recipes
Anchors
| ^ | Start of string | |
| $ | End of string | |
| \b | Word boundary | |
| \B | Not a word boundary |
Character classes
| . | Any character except newline | |
| \d | Digit (0-9) | |
| \D | Not a digit | |
| \w | Word character (letter, digit, _) | |
| \W | Not a word character | |
| \s | Whitespace (space, tab, newline) | |
| \S | Not whitespace | |
| [abc] | Any of a, b or c | |
| [^abc] | Any character except a, b, c | |
| [a-z] | Any character in range a-z |
Quantifiers
| * | Zero or more | |
| + | One or more | |
| ? | Zero or one (optional) | |
| {n} | Exactly n times | |
| {n,} | n or more times | |
| {n,m} | From n to m times | |
| *? | Lazy: as few as possible |
Groups & references
| (abc) | Capturing group | |
| (?:abc) | Non-capturing group | |
| (a|b) | Alternation: a or b | |
| (?<name>…) | Named group | |
| \1 | Backreference to group 1 | |
| (?=…) | Lookahead: followed by | |
| (?!…) | Negative lookahead |
Flags
| g | Global: all matches | |
| i | Ignore case | |
| m | Multiline: ^ $ per line | |
| s | Dot matches newline | |
| u | Unicode mode | |
| y | Sticky: from lastIndex only |
regex
Frequently asked questions
How do I read a regex?
Start from the left: each token matches one thing — ^ is string start, \d is a digit, + means "one or more". Click any token here to add it to your pattern.
What flags should I use?
g finds all matches, i ignores case, m makes ^ and $ match line starts/ends, s lets . match newlines, u enables Unicode mode.
How do I test an email pattern?
Choose the Email recipe, paste your text into the test field and see highlighted matches and their count immediately.