Regex Cheatsheet
Interactive regex syntax reference with descriptions, examples, and a try-it-live tester for each pattern.
Regex Cheatsheet tool
Example
Input: Word Boundary \bcat\b, tried live on the text "the cat sat in concatenate"
Result: 1 match: the standalone word "cat". The "cat" inside "concatenate" is not matched
\b matches the position between a word character and a non-word character, so the pattern only finds cat as a whole word.
Core Regex Tokens
| Token | Meaning | Example | Matches |
|---|---|---|---|
| . | Any character except newline | a.c | abc, a1c, a-c |
| \d | Digit (0-9) | \d+ | 42, 007, 2026 |
| \w | Letter, digit or underscore | \w+ | hello_42 |
| \s | Whitespace | a\sb | a b |
| [abc] | Any one of the listed characters | [aeiou] | a, e, i, o, u |
| [^abc] | Any character not listed | [^0-9] | a, !, space |
| ^ | Start of string or line | ^Hello | Hello world |
| $ | End of string or line | world$ | Hello world |
| \b | Word boundary | \bcat\b | the cat sat |
| * | Zero or more | ab*c | ac, abc, abbc |
| + | One or more | ab+c | abc, abbc |
| ? | Zero or one | colou?r | color, colour |
| {n,m} | Between n and m times | \d{2,4} | 42, 123, 1234 |
| (abc) | Capturing group | (\d{3})-(\d{4}) | 555-1234 |
| a|b | Either side | cat|dog | cat or dog |
Examples taken from the entries in this cheatsheet.
- Browse regex syntax elements by category (character classes, anchors, quantifiers, groups and lookarounds, flags), or type in the search box to filter them.
- Click on any pattern element to see its description, an example pattern, and sample text it matches.
- Use the inline mini-tester for each element to type a test string and see matches highlighted in real time.
- Try different test strings in the mini-tester, including ones that should not match, to understand exactly how the syntax works.
- Scroll to the "Common Patterns" section to find ready-to-use regexes for emails, URLs, phone numbers, and more.
- Copy any pattern or example using the copy button to paste it directly into your code.
Regex Syntax Cheat Sheet with Live Examples
This regex cheatsheet explains the building blocks of regular expressions one at a time. Each has an example and a small live tester. There are 46 entries in six groups: character classes, anchors, quantifiers, groups and references, flags, and common patterns.
A regular expression is a pattern for finding text. Most of it is ordinary characters that match themselves, plus a few symbols with special meaning. \d means any digit, + means one or more of the item before it, and ^ ties the match to the start. Together, ^\d+ matches the digits at the start of a line. Learning the pieces one by one, as they are laid out here, is much easier than decoding a finished pattern.
Open any entry to see its description, an example pattern and sample text it matches. Then type your own text into its mini tester, and matches are highlighted and counted as you type. The tester runs the example rather than the placeholder, so for {n} it tries \d{3}. Try text that should fail too. Seeing why \bcat\b skips the cat inside concatenate teaches more than a match does. The pattern and the example each have a copy button. The search box at the top filters entries by pattern, name or description.
The syntax is JavaScript's, which most languages share for the basics. The Common Patterns group has starting points for emails, URLs, E.164 phone numbers, IPv4 addresses, ISO dates, hex colors, prices and strong passwords, with their limits noted. When you are ready to build a full pattern against real data, move to the Regex Tester.
Sources
Frequently Asked Questions
Related Tools
Regex Tester
Test regular expressions with real-time match highlighting, group capture display, and a pattern library.
Developer ToolsGit Cheatsheet
Searchable interactive Git command reference organized by workflow - branching, merging, rebasing, and more.
DevOps ToolsFind and Replace
Find and replace text with regular expressions, capture groups, case-sensitive matching, and a live match count.
Text and Writing