Regex Cheatsheet (2026): 30 Practical Patterns Every Developer Uses
Regex can be either a superpower or a maintenance nightmare. The difference is not intelligenceâit is pattern discipline.
This cheatsheet focuses on practical, reusable patterns developers use in APIs, forms, logs, and search tooling.
Core Regex Building Blocks
^start of string$end of string.any character*zero or more+one or more?optional[]character class()capture group(?:)non-capturing group\ddigit,\wword,\swhitespace
30 Useful Patterns
- Email (basic):
^[^\s@]+@[^\s@]+\.[^\s@]+$ - URL (basic):
^https?:\/\/.+ - Hex color:
^#(?:[0-9a-fA-F]{3}){1,2}$ - UUID v4 (strict):
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ - Strong password (example policy):
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{12,}$ - ISO date:
^\d{4}-\d{2}-\d{2}$ - Time 24h:
^(?:[01]\d|2[0-3]):[0-5]\d$ - Integer:
^-?\d+$ - Decimal number:
^-?\d+(?:\.\d+)?$ - HTML tag (rough):
<[^>]+> - Multiple spaces:
\s{2,} - Leading/trailing spaces:
^\s+|\s+$ - Repeated word:
\b(\w+)\s+\1\b - Slug-safe text:
^[a-z0-9]+(?:-[a-z0-9]+)*$ - Username (3-20):
^[a-zA-Z0-9_]{3,20}$ - IPv4 (basic):
^(?:\d{1,3}\.){3}\d{1,3}$ - JWT token shape:
^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$ - Base64 (simple):
^[A-Za-z0-9+/]+={0,2}$ - Markdown heading:
^#{1,6}\s.+$ - CSV value in quotes:
"(?:[^"]|"")*" - US ZIP:
^\d{5}(?:-\d{4})?$ - Phone (generic):
^\+?[0-9\s()-]{7,20}$ - Credit card shape (not validation):
^\d{13,19}$ - Remove non-alphanumerics:
[^a-zA-Z0-9] - Find TODO comments:
\bTODO\b.* - JS import lines:
^import\s.+from\s['"].+['"];?$ - Trailing comma before brace:
,\s*([}\]]) - Duplicate blank lines:
\n{3,} - File extension:
\.([a-zA-Z0-9]+)$ - Non-ASCII characters:
[^\x00-\x7F]
Performance Tips (Very Important)
- Avoid catastrophic backtracking (
(a+)+style patterns) - Prefer explicit classes over greedy
.*when possible - Anchor patterns when validating full strings (
^...$) - Benchmark heavy regex in production-critical paths
Regex Debugging Workflow
- Build pattern iteratively in Regex Tester
- Generate starter expressions in Regex Generator
- Validate payload wrappers using JSON Formatter
Maintainability Rules for Teams
- Keep regex in named constants, not inline one-liners everywhere
- Add test cases for valid/invalid samples
- Comment the business rule in plain language
- Prefer readability over âcleverâ minimization
FAQ
Is regex enough for email validation?
Good for basic syntax checks. Use confirmation workflows for true validation.
Why do regexes break across languages?
Engines differ in features and flags. Always test in your target runtime.
Should I use regex to parse HTML?
For full parsing, use an HTML parser. Regex is okay for narrow extraction tasks.
What is catastrophic backtracking?
A performance failure mode where certain inputs cause exponential matching time.
Final Take
Regex becomes a force multiplier when you standardize patterns, test them, and keep them readable. Start with proven patterns and adapt intentionally.
Use the Regex Tester for safe, iterative validation before shipping patterns into production logic.
Tags
Popular Free Tools
JSON Formatter & Validator
Format, beautify, and validate JSON data with syntax highlighting.
Image Compressor
Compress images to reduce file size without losing quality.
Password Generator
Generate strong, secure random passwords with custom options.
Base64 Encoder/Decoder
Encode plain text or binary data to Base64 or decode Base64 strings back to text instantly. 100% client-side â your data never leaves the browser.
Word Counter
Count words, characters, sentences, paragraphs, and reading time instantly. Privacy-first Word Counter with keyword density â text never leaves your browser.
Hash Generator
Generate MD5, SHA-1, SHA-256, and SHA-512 hashes.
Color Picker & Converter
Pick colors and convert between HEX, RGB, HSL, CMYK with shades and contrast preview.
Markdown to HTML
Convert Markdown text to clean, ready-to-use HTML code instantly. Supports headings, links, lists, code blocks, and inline formatting â no server required.
Related Guides
Waitlist Launching Soon
Join the waitlist â no backend signup required.
No database required for this waitlist. Once you join, this form stays hidden on this device.