April 4, 2026 2 min readUpdated Apr 9, 2026
Regex Cheat Sheet for Developers: Common Patterns
regexcheat-sheetjavascriptpythonbackend

Regex Fundamentals
Regular expressions (regex) are patterns used to match character combinations in strings. Supported in JavaScript, Python, Go, Java, Ruby, PHP, and virtually every other language.
Core Syntax Quick Reference
| Token | Meaning |
|---|---|
. | Any character except newline |
\d | Digit (0–9) |
\w | Word character (a-z, A-Z, 0-9, _) |
\s | Whitespace (space, tab, newline) |
^ | Start of string |
$ | End of string |
* | 0 or more |
+ | 1 or more |
? | 0 or 1 (optional) |
{n,m} | Between n and m times |
[abc] | Character class (a, b, or c) |
[^abc] | Negated class (not a, b, or c) |
| `(a | b)` |
(?:...) | Non-capture group |
(?=...) | Positive lookahead |
Common Patterns
Email Address
^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$
URL (HTTP/HTTPS)
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)
IPv4 Address
^((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]?)$
Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
Hex Color Code
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
UUID v4
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
Slug (URL-safe string)
^[a-z0-9]+(?:-[a-z0-9]+)*$
Strong Password
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
Requires: 1 lowercase, 1 uppercase, 1 digit, 1 special character, min 8 chars.
Practical JavaScript Examples
// Test a pattern
const emailRegex = /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/;
console.log(emailRegex.test('user@example.com')); // true
// Extract all matches
const text = 'Call 555-867-5309 or 800-555-1212';
const phones = text.match(/(\d{3}[-.]\d{3}[-.]\d{4})/g);
// ['555-867-5309', '800-555-1212']
// Replace with capture groups
'2026-04-09'.replace(/^(\d{4})-(\d{2})-(\d{2})$/, '$2/$3/$1');
// '04/09/2026'
Flags Reference
| Flag | Meaning |
|---|---|
g | Global — find all matches |
i | Case-insensitive |
m | Multiline — ^ and $ match line starts/ends |
s | Dotall — . matches newline too |
Test Your Regex Online
Use the free Regex Tester on konvertio.app — enter your pattern and test string, see matches highlighted in real time, and understand capture groups at a glance.