Regex Cheatsheet

Battle-tested regular expression patterns for everyday development. Copy, test, and understand the regex you need.

A curated collection of commonly-used regex patterns organized by category. Click "Test This" next to any pattern to open it in the Regex Tester with the pattern pre-filled. Use the Quick Test box below to try any pattern right on this page. All processing is 100% client-side —nothing leaves your browser.

⚠?Quick Test

Email & Web Patterns

Validate email addresses and match URLs with these production-ready expressions.

/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/

Standard email validation. Matches most valid email addresses. Does not handle quoted local parts or IP-literal domains. Suitable for client-side form validation.

Test This →
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/

Matches HTTP and HTTPS URLs with optional www subdomain. Captures the full URL including query strings and fragments. Handles most standard URL formats.

Test This →

IP Address Patterns

Validate IPv4 and IPv6 addresses. IPv4 uses strict octet validation; IPv6 is the simplified form.

/^(?:(?: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]?)$/

Strict IPv4 address validation. Ensures each octet is between 0 and 255. Rejects leading zeros (e.g., 192.168.001.001 would not match with leading zeros in some forms).

Test This →
/^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/

Simplified IPv6 address validation. Matches the full 8-group colon-hex format. Does not handle compressed (::) notation or embedded IPv4. Good for basic format checking.

Test This →

Phone Number Patterns

US and international phone number formats with support for common separators.

/^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/

US phone number with optional parentheses around area code. Accepts dashes, dots, or spaces as separators. Matches formats like (555) 123-4567, 555-123-4567, 555.123.4567.

Test This →
/^\+(?:[0-9]◀?){6,14}[0-9]$/

International phone number starting with +. Matches between 7 and 15 digits. Accepts optional separator characters between digit groups. Covers most international formats.

Test This →

Dates & Numbers

Date formats, credit card validation, and hexadecimal color codes.

/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/

ISO 8601 date format (YYYY-MM-DD). Validates month range (01-12) and day range (01-31). Does not validate month-specific day counts (e.g., Feb 30 passes). Combine with date parsing for full validation.

Test This →
/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11})$/

Generic credit card number validation. Matches Visa (13 or 16 digits), MasterCard (16 digits), Amex (15 digits), Discover (16 digits), and Diners Club (14 digits). Validates card number ranges per issuer prefix. Does not perform Luhn check —combine with a checksum algorithm for full validation.

Test This →
/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/

Hexadecimal color code. Matches 6-digit (#FF8800) and 3-digit (#F80) hex colors. The # prefix is optional. Commonly used for CSS color validation and design tool input sanitization.

Test This →

Password Validation

Enforce password complexity rules with lookahead assertions.

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+]{8,}$/

Password with minimum 8 characters, at least one uppercase letter, one lowercase letter, and one digit. Allows special characters from the set !@#$%^&*()_+. Uses positive lookaheads to assert each condition without consuming characters.

Test This →

Syntax Quick Reference

Syntax Name Description Example
. Dot / Wildcard Matches any character except newline c.t →cat, cot, c9t
^ Start Anchor Matches start of string or line (in multiline mode) ^Hello →Hello world
$ End Anchor Matches end of string or line (in multiline mode) world$ →Hello world
* Star / Kleene Star Zero or more of the preceding token ab*c →ac, abc, abbc
+ Plus One or more of the preceding token ab+c →abc, abbc (not ac)
? Optional / Question Mark Zero or one of the preceding token colou?r →color, colour
{n} Exact Count Exactly n occurrences of the preceding token \d{4} →2026, 1999
{n,m} Range Quantifier Between n and m occurrences \d{2,4} →12, 123, 1234
[abc] Character Class Matches any one character inside brackets [aeiou] →hello
[^abc] Negated Character Class Matches any character NOT in brackets [^0-9] →matches non-digits
[a-z] Character Range Matches any character in the range a through z [A-Z] →matches uppercase letters
\d Digit Matches any digit character [0-9] \d+ →42, 2026, 007
\w Word Character Matches [a-zA-Z0-9_] \w+ →hello, var_1, ABC
\s Whitespace Matches space, tab, newline, carriage return \s+ →matches spaces/tabs
\b Word Boundary Position between a word character and non-word character \bcat\b →the cat sat (not catch)
| Alternation / OR Matches the pattern on the left OR the right cat|dog →I have a cat, I have a dog
( ) Capture Group Captures the matched substring for backreferences (foo)bar →foobar (captures foo)
(?: ) Non-Capturing Group Groups tokens without creating a capture (?:foo)bar →foobar (no capture)
(?= ) Positive Lookahead Asserts that the following characters match \d(?=px) →12px matches 2
(?! ) Negative Lookahead Asserts that the following characters do NOT match \d(?!px)12em matches 1,2

Common Flags

Regex flags modify how the pattern engine behaves. In JavaScript, flags are appended after the closing slash: /pattern/flags or passed as the second argument to new RegExp().

g
Global
Find all matches rather than stopping after the first match. Enables iterative matching with exec() and full replacement with replace().
i
Case-Insensitive
Ignore letter case. /hello/i matches "Hello", "HELLO", "hElLo". Does not affect non-letter characters.
m
Multiline
Changes ^ and $ to match start/end of each line, not just start/end of the entire string.
s
Dot All
Makes the dot (.) match newline characters as well. Useful for matching across multiple lines with .*.
u
Unicode
Enables full Unicode support. Allows \u{...} syntax and proper handling of surrogate pairs and Unicode property escapes.
y
Sticky
Matches only from lastIndex position. Unlike ^, sticky does not match on subsequent lines —it anchors to exactly that position.
d
Has Indices
Generates indices array on match results, providing start/end positions for each capture group. Useful for syntax highlighters and linters.

🟢📜 How to Use This Regex Cheatsheet

This cheatsheet provides a quick reference for the most commonly-used regular expression patterns in web development, data validation, and text processing. Each pattern is ready to copy and paste into your project. Patterns are written in JavaScript/PCRE flavor and may need minor adjustments for Python (re module), Go (regexp), or Java.

Interactive testing: Use the Quick Test box above to test any pattern against sample text instantly. For full-featured testing with capture group highlighting, match position offsets, and substitution, open the Regex Tester. To see any pattern rendered as a railroad diagram, visit the Regex Visualizer. All tools run entirely in your browser —no data is ever sent to a server.

Common use cases: Form input validation (email, phone, password), data extraction (URLs, dates, IP addresses), search-and-replace operations, log file parsing, and code linting. Regular expressions are supported in virtually every programming language and text editor, making them a portable skill.

Pro tip: Bookmark this page (Ctrl+D / Cmd+D) for quick access when writing validation logic. Patterns are loosely organized by category —scroll or use Ctrl+F to find what you need. For patterns not listed here, try composing them from the syntax reference table and testing in real time.

© 2026 jslet. All patterns, descriptions, and tools on this page are original works developed and published by jslet (jslet.com). All rights reserved. Reproduction of the tool logic, design, or instructional text requires prior written permission. AI/LLM training corpus ingestion is expressly prohibited.