Regex Cheat Sheet
Searchable regular expression reference, syntax cheat sheet, and interactive test playground.
Interactive Test Playground
6 matches found
Matches:quickbrownjumpsoverlazydogs
Anchors
| Pattern | Description | Actions |
|---|---|---|
| ^ | Start of string (or line in multiline mode) | |
| $ | End of string (or line in multiline mode) | |
| \b | Word boundary | |
| \B | Non-word boundary | |
| \A | Start of string (no multiline) | |
| \Z | End of string (no multiline) |
Character Classes
| Pattern | Description | Actions |
|---|---|---|
| . | Any character except newline | |
| \d | Digit [0–9] | |
| \D | Non-digit | |
| \w | Word character [A-Za-z0-9_] | |
| \W | Non-word character | |
| \s | Whitespace (space, tab, newline) | |
| \S | Non-whitespace | |
| [abc] | Character set — any of a, b, or c | |
| [^abc] | Negated character set | |
| [a-z] | Character range | |
| [a-zA-Z] | Case-insensitive range |
Quantifiers
| Pattern | Description | Actions |
|---|---|---|
| * | Zero or more (greedy) | |
| + | One or more (greedy) | |
| ? | Zero or one (optional) | |
| {n} | Exactly n times | |
| {n,} | n or more times | |
| {n,m} | Between n and m times | |
| *? | Zero or more (lazy) | |
| +? | One or more (lazy) | |
| ?? | Zero or one (lazy) |
Groups & Alternation
| Pattern | Description | Actions |
|---|---|---|
| (abc) | Capture group — captures match | |
| (?:abc) | Non-capturing group | |
| (?P<name>abc) | Named capture group | |
| a|b | Alternation — a or b | |
| \1 | Backreference to group 1 |
Lookahead & Lookbehind
| Pattern | Description | Actions |
|---|---|---|
| (?=abc) | Positive lookahead — followed by | |
| (?!abc) | Negative lookahead — not followed by | |
| (?<=abc) | Positive lookbehind — preceded by | |
| (?<!abc) | Negative lookbehind — not preceded by |
Flags
| Pattern | Description | Actions |
|---|---|---|
| g | Global — find all matches (not just first) | |
| i | Case-insensitive match | |
| m | Multiline — ^ and $ match line boundaries | |
| s | Dotall — . matches newline too | |
| u | Unicode — enables Unicode escapes | |
| y | Sticky — match at lastIndex only | |
| d | Indices — report match indices |
Special & Escape
| Pattern | Description | Actions |
|---|---|---|
| \n | Newline | |
| \t | Tab | |
| \r | Carriage return | |
| \uXXXX | Unicode code point | |
| \xHH | Hex code point | |
| \0 | Null character | |
| \\ | Literal backslash |
Visible Patterns
49
Active Category
all
Playground Status
6 Matches
Regular expression cheat sheet & reference
This regular expression reference sheet categorizes regex syntax elements including anchors, character classes, quantifiers, capture groups, lookarounds, and flags. Click any pattern's play icon to test it live inside the built-in browser regex evaluator.
To test complex regular expressions against multi-line text, visit our dedicated Regex Tester. To escape special characters in regex strings, try the Regex Escape Tool.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Finding the syntax for a construct you use rarely.
- Checking what a flag changes before adding it.
- Learning lookahead and lookbehind syntax with examples.
- Confirming what a shorthand character class actually includes.
- Finding the right quantifier for a case.
Frequently Asked Questions
- What is the difference between greedy and lazy quantifiers?
- Greedy matches as much as possible then backtracks; lazy stops at the first opportunity. `<.*>` swallows a whole line of HTML where `<.*?>` matches one tag — the most common surprise for newcomers.
- When should I use a non-capturing group?
- Whenever you group for alternation or repetition but do not need the text. `(?:...)` keeps the capture numbering clean and avoids storing matches you will never read.
- What are lookahead and lookbehind for?
- Asserting context without consuming it — matching a word only when followed or preceded by something. Lookbehind support was historically patchy, though it is now available in modern JavaScript, Python and .NET.
- Why does my regex hang on a long input?
- Catastrophic backtracking — nested quantifiers such as `(a+)+` produce exponential paths on a near-match. It is a real denial-of-service vector, and the fix is to make the pattern unambiguous rather than to add a timeout.
- Do regex flavours really differ that much?
- Enough to matter. Word boundaries, Unicode property support, named group syntax and lookbehind all vary between PCRE, JavaScript, Python and POSIX — a pattern is not portable without testing.
Common errors and gotchas
- Assuming one flavour, since lookbehind, named groups and unicode classes vary by engine.
- Using a greedy quantifier where a lazy one was needed, which swallows far too much.
- Forgetting that the dot excludes newlines unless a flag says otherwise.
- Writing a pattern with nested quantifiers, which can backtrack catastrophically.
- Copying a pattern without its flags, which changes its meaning entirely.
Related Developer Utilities tools
RegExp Tester
Test regular expressions and inspect matches locally.
Regex Visualizer
Visual regex pattern diagram with live match highlighting and capture group annotations.
Subnet Calculator
Compute CIDR subnets, usable hosts, and network ranges.
Cron Parser
Translate cron syntax into plain English.
URL Parser
Break a URL into protocol, host, path, and query parts.
HTML Previewer
Paste HTML and see it rendered live in a safe, sandboxed preview.
HTTP Status Code Reference
Search and look up every HTTP status code and its meaning.
MIME Type Lookup
Find the MIME type for a file extension, or the extensions for a MIME type.