Regular Expressions (Regex) Developer Cheat Sheet & Quick Recipes
Complete modern regular expression cheat sheet. Master character classes, quantifiers, lookahead, lookbehind, capturing groups, and copy-paste production recipes.
Interactive Regex Tester & Visualizer
Live Interactive SandboxValidates standard user@domain.tld email addresses with case insensitivity. Test the preset input below or customize it before launching into the full workspace.
Regular expressions (Regex) are essential across every layer of software development: API validation, log filtering, data extraction, search & replace in IDEs, and security firewalls.
This reference cheat sheet condenses syntax, meta-characters, advanced assertions, and copy-paste production recipes into a quick-lookup format.
1. Core Meta-Characters & Anchors
| Symbol | Meaning | Example | Matches |
|---|---|---|---|
^ |
Start of string / line | ^Error |
Line starting with "Error" |
$ |
End of string / line | \.json$ |
Strings ending in ".json" |
. |
Any single character (except newline) | c.t |
"cat", "cot", "c9t" |
\b |
Word boundary | \bdev\b |
"dev" inside "dev tools", but not "developer" |
\B |
Non-word boundary | \Bdev\B |
Matches "dev" only when embedded inside words |
| |
Alternation (OR) | cat|dog |
Either "cat" or "dog" |
2. Character Classes
| Class | Equivalent | Description |
|---|---|---|
\d |
[0-9] |
Any digit |
\D |
[^0-9] |
Any non-digit |
\w |
[a-zA-Z0-9_] |
Word character (alphanumeric + underscore) |
\W |
[^a-zA-Z0-9_] |
Non-word character (spaces, symbols) |
\s |
[ \t\r\n\f\v] |
Whitespace character |
\S |
[^ \t\r\n\f\v] |
Non-whitespace character |
[abc] |
Discrete set | Either "a", "b", or "c" |
[^abc] |
Negated set | Any character except "a", "b", or "c" |
[a-z] |
Range | Lowercase ASCII letters |
3. Quantifiers: Greedy vs Lazy
Quantifiers control how many times a character or group may repeat. By default, quantifiers are greedy (they consume as much text as possible). Append ? to make them lazy (consume as few characters as possible).
| Greedy | Lazy | Frequency |
|---|---|---|
* |
*? |
0 or more times |
+ |
+? |
1 or more times |
? |
?? |
0 or 1 time (optional) |
{n} |
N/A | Exactly n times |
{n,} |
{n,}? |
At least n times |
{n,m} |
{n,m}? |
Between n and m times |
4. Groups, Backreferences & Assertions
Capturing vs Non-Capturing Groups
(pattern): Captures the match into a numeric group ($1,$2).(?<name>pattern): Named capture group (accessible viagroups.namein JS/Python).(?:pattern): Non-capturing group. Groups tokens together for repetition without allocating memory.
Lookahead and Lookbehind (Zero-Width Assertions)
| Syntax | Name | Logic |
|---|---|---|
(?=abc) |
Positive Lookahead | Matches if followed by "abc" |
(?!abc) |
Negative Lookahead | Matches if NOT followed by "abc" |
(?<=abc) |
Positive Lookbehind | Matches if preceded by "abc" |
(?<!abc) |
Negative Lookbehind | Matches if NOT preceded by "abc" |
5. Verified Copy-Paste Production Recipes
A. Validating UUID v4
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$
B. IPv4 Address (0-255 Range Safe)
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
C. Strong Password Enforcement
Requires at least 8 characters, one uppercase, one lowercase, one digit, and one symbol:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
D. ISO 8601 Date Format (YYYY-MM-DD)
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$
E. Semantic Versioning (SemVer)
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
Live Tool: Regex Tester & Matcher
Client-Side EngineReal-time RegExp testing with flags (g, i, m, s), match lists, and substitution preview.