Blog
Custom Print on Demand Apparel — Free Storefront for Your Business
Wild & Free Tools

Regex Cheat Sheet — 20 Common Patterns with Examples You Can Test

Last updated: April 20268 min readDeveloper Tools

Twenty regex patterns you will actually use. Each one includes the pattern, what it matches, and a test example. Copy any pattern and test it instantly against your own data.

Text & Validation Patterns

#Pattern NameRegexExample Match
1Email address[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}[email protected]
2URL (http/https)https?://[^\\s/$.?#][^\\s]*https://example.com/page?q=1
3IPv4 address\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b192.168.1.1
4US phone number\\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4}(555) 123-4567
5Date (YYYY-MM-DD)\\d{4}-\\d{2}-\\d{2}2026-04-01
6US zip code\\d{5}(-\\d{4})?90210, 90210-1234
7Hex color code#[0-9a-fA-F]{3,8}#FF5733, #fff, #00aaff80

Data Extraction Patterns

#Pattern NameRegexExample Match
8HTML tags<[^>]+><div class="box">, <br/>
9Username (alphanumeric)^[a-zA-Z0-9_]{3,20}$cool_user_42
10Password strength (8+ chars, upper, lower, digit)^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}$MyPass123
11Credit card (basic 16 digits)\\b\\d{4}[- ]?\\d{4}[- ]?\\d{4}[- ]?\\d{4}\\b4111-1111-1111-1111
12File extension\\.([a-zA-Z0-9]{1,10})$.pdf, .jpg, .html
13Trim whitespace^\\s+|\\s+$Leading/trailing spaces
14Duplicate consecutive words\\b(\\w+)\\s+\\1\\bthe the, is is

Developer & Content Patterns

#Pattern NameRegexExample Match
15Markdown link\\[([^\\]]+)\\]\\(([^)]+)\\)[text](https://url.com)
16CSV value (quoted)"([^"]*)""John Smith","New York"
17JSON key"([^"]+)"\\s*:"name": "value"
18URL slug^[a-z0-9]+(-[a-z0-9]+)*$my-blog-post-title
19Emoji (Unicode range)[\\u{1F600}-\\u{1F64F}]Matches face emojis
20Hashtag#[a-zA-Z0-9_]+#regex, #coding, #dev_tools

How to Use This Cheat Sheet

  1. Find the pattern you need from the tables above
  2. Copy the regex pattern
  3. Open Regex Tester
  4. Paste the pattern and your test data
  5. Verify it matches what you expect (and does not match what it should not)
  6. Copy the working pattern into your code

Always test against edge cases, not just the happy path. An email regex that matches "[email protected]" might also match "[email protected]" if you are not careful.

Quick Syntax Reference

SymbolMeaningExample
\\dAny digit (0-9)\\d{3} matches 123
\\wWord character (letter, digit, underscore)\\w+ matches hello_42
\\sWhitespace (space, tab, newline)\\s+ matches any whitespace run
.Any character (except newline without s flag)a.c matches abc, a1c, a-c
+One or more of previous\\d+ matches 1, 42, 999
*Zero or more of previous\\d* matches empty string or digits
?Zero or one of previous (also: lazy modifier)colou?r matches color and colour
{n,m}Between n and m repetitions\\d{2,4} matches 42, 123, 1234
^Start of string (or line with m flag)^ matches start of string
$End of string (or line with m flag)$ matches end of string
[abc]Character class: a, b, or c[aeiou] matches any vowel
[^abc]Negated class: NOT a, b, or c[^0-9] matches non-digits
(abc)Capture group(\\d+)-(\\d+) captures both numbers
a|bAlternation: a or bcat|dog matches either word
\\bWord boundary\\bcat\\b matches cat but not catalog

Related Developer Tools

Copy a pattern, test it, ship it — all in your browser.

Open Regex Tester
Launch Your Own Clothing Brand — No Inventory, No Risk