Regex Cheatsheet
Quick reference for regular expression syntax
Anchors
| ^ | Start of string (or line with m flag) |
| $ | End of string (or line with m flag) |
| \b | Word boundary |
| \B | Non-word boundary |
| \A | Start of string (no multiline) |
| \Z | End of string (no multiline) |
Character Classes
| [abc] | Any of a, b, or c |
| [^abc] | Not a, b, or c |
| [a-z] | Lowercase a through z |
| [A-Z] | Uppercase A through Z |
| [0-9] | Digit 0 through 9 |
| [a-zA-Z] | Any letter |
| . | Any character except newline |
| \w | Word char [a-zA-Z0-9_] |
| \W | Non-word character |
| \d | Digit [0-9] |
| \D | Non-digit |
| \s | Whitespace (space, tab, newline) |
| \S | Non-whitespace |
Quantifiers
| * | 0 or more (greedy) |
| + | 1 or more (greedy) |
| ? | 0 or 1 (optional) |
| {n} | Exactly n times |
| {n,} | n or more times |
| {n,m} | Between n and m times |
| *? | 0 or more (lazy) |
| +? | 1 or more (lazy) |
| ?? | 0 or 1 (lazy) |
Flags
| g | Global — find all matches |
| i | Case-insensitive |
| m | Multiline — ^ and $ match line boundaries |
| s | Dotall — . matches newlines |
| u | Unicode support |
| y | Sticky — match at lastIndex only |
Groups & Lookarounds
| (abc) | Capturing group |
| (?:abc) | Non-capturing group |
| (?<name>abc) | Named capturing group |
| (?=abc) | Positive lookahead |
| (?!abc) | Negative lookahead |
| (?<=abc) | Positive lookbehind |
| (?<!abc) | Negative lookbehind |
| \1 | Back-reference to group 1 |
| \k<name> | Back-reference to named group |
Escape Sequences
| \n | Newline |
| \t | Tab |
| \r | Carriage return |
| \0 | Null character |
| \uXXXX | Unicode code point |
| \\ | Literal backslash |
| \. | Literal dot |
Common Patterns
| ^\d+$ | Integer (digits only) |
| ^\d*\.?\d+$ | Decimal number |
| ^-?\d+$ | Integer (optional negative) |
| ^\w+$ | Alphanumeric + underscore only |
| ^[a-zA-Z]+$ | Letters only |
| ^\s*$ | Empty or whitespace only |
| \S+ | One or more non-whitespace |
Useful Recipes
| ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$ | Email (simplified) |
| ^\d{4}-\d{2}-\d{2}$ | Date YYYY-MM-DD |
| ^#[0-9a-fA-F]{3,6}$ | Hex color |
| ^https?:\/\/ | URL starting with http(s) |
| ^\+?[\d\s\-()]{7,}$ | Phone number (loose) |
| ^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$ | UUID v4 |
| ^(?=.*[A-Z])(?=.*\d).{8,}$ | Password (min 8, uppercase, digit) |
Want a deeper explanation? Read the Regex Guide or jump straight to the Regex Tester.
Online Regular Expression Tester
io9.me Regex Tester lets you write and test JavaScript regular expressions with instant visual feedback. Type a pattern and test string, and matches are highlighted in real time. Capture groups are extracted and displayed alongside each match.
Features
- Live matching — see results instantly as you type the pattern or test string
- Capture groups — view numbered and named groups for every match
- All JavaScript flags — global (g), case-insensitive (i), multiline (m), dotAll (s), unicode (u), sticky (y)
- Color-coded match highlighting in the test string
- Quick-reference cheatsheet for regex syntax
- Replace mode to test substitution patterns
How to use
- Enter a regex pattern in the pattern field.
- Toggle flags (g, i, m, etc.) as needed.
- Paste or type your test string below.
- Matches are highlighted in real time; capture groups appear in the results panel.
Common regex patterns
- Email validation: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
- URL matching: https?:\/\/[^\s]+
- IP address: \b\d{1,3}(\.\d{1,3}){3}\b
- Date (YYYY-MM-DD): \d{4}-\d{2}-\d{2}