TextSorter

Regex Cheat Sheet 2026 — Common Patterns with Live Examples

· 6 min read

This regex cheat sheet covers the patterns developers and data analysts reach for most often — email, URL, phone, date, IP, hex color, and more — with a syntax reference you can test immediately in TextSorter's free online Regex Tester.

What Do Regex Syntax Symbols Mean?

Character Classes

  • . — Any single character except newline
  • \d — Any digit (0–9). Equivalent to [0-9]
  • \D — Any non-digit character
  • \w — Any word character (letters, digits, underscore)
  • \W — Any non-word character
  • \s — Any whitespace (space, tab, newline)
  • [abc] — Any one of a, b, or c
  • [^abc] — Any character NOT a, b, or c
  • [a-z] — Any lowercase letter a through z

Quantifiers

  • * — 0 or more times (greedy)
  • + — 1 or more times (greedy)
  • ? — 0 or 1 time (optional)
  • {n} — Exactly n times
  • {n,m} — Between n and m times
  • *? / +? — Lazy (non-greedy) — stops at shortest match

Anchors and Boundaries

  • ^ — Start of line
  • $ — End of line
  • \b — Word boundary

Groups

  • (abc) — Capturing group
  • (?:abc) — Non-capturing group (faster, no backreference)
  • a|b — Match "a" OR "b"
  • (?=abc) — Positive lookahead
  • (?!abc) — Negative lookahead

What Are the Most Useful Regex Patterns?

Email Address

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

Matches: [email protected], [email protected]
Note: No regex can fully validate email — only sending a confirmation message can.

URL (HTTP/HTTPS)

https?:\/\/[^\s<>"'\)\]]+

Matches: https://example.com/path?query=1, http://sub.domain.org

US Phone Number

(?:\+?1[\s.\-]?)?\(?\d{3}\)?[\s.\-]?\d{3}[\s.\-]?\d{4}

Matches: (555) 123-4567, 555.123.4567, +1 555 123 4567, 5551234567

International Phone (E.164)

\+[1-9]\d{6,14}

Matches: +14155552671, +447911123456, +33123456789

IPv4 Address

\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b

Matches: 192.168.1.1, 255.255.255.0 · Rejects: 999.1.1.1

Date — YYYY-MM-DD (ISO 8601)

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

Matches: 2026-03-15 · Rejects: 2026-13-01 (month 13)

Date — MM/DD/YYYY (US)

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

Matches: 03/15/2026, 12/31/1999

Time — HH:MM (24-hour)

([01]\d|2[0-3]):[0-5]\d

Matches: 09:30, 23:59 · Rejects: 25:00

Hex Color Code

#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})

Matches: #1a2b3c, #fff, #FF6347

US ZIP Code

\b\d{5}(?:-\d{4})?\b

Matches: 90210, 10001-1234

Credit Card (16-digit format)

\b(?:\d{4}[\s\-]?){3}\d{4}\b

Note: Matches format only. Use a Luhn algorithm to validate the actual number.

HTML Tag

<[^>]+>

Matches: <p>, <div class="wrap">, </span>

Blank Lines

^\s*$

Use case: Find & remove empty lines using your editor's regex-enabled Find & Replace.

Repeated Words

\b(\w+)\s+\1\b

Matches: the the, is is — catches accidental double words in writing.

What Are Regex Flags and When Should You Use Them?

  • i — Case-insensitive. /hello/i matches "Hello", "HELLO", "hello".
  • g — Global. Find all matches, not just the first one.
  • m — Multiline. Makes ^ and $ match the start/end of each line.
  • s — Dotall. Makes . match newline characters too.

Quick Tips for Writing Reliable Regex

  • Always escape special characters when matching them literally — write \. to match a period, not . which matches any character.
  • Use non-capturing groups (?:...) when you need to group without capturing — it's faster and cleaner.
  • Prefer lazy quantifiers +? when extracting content between delimiters to avoid over-matching.
  • Test on real data — paste your actual text into TextSorter's Regex Tester before applying patterns in production.

Frequently Asked Questions

What's the difference between a capturing group and a non-capturing group?

A capturing group (abc) stores the matched text for use in backreferences or replace operations. A non-capturing group (?:abc) groups the pattern without storing the result — it's more efficient when you only need grouping for quantifier purposes.

Why does my regex match too much text?

You're likely using a greedy quantifier (+ or *). Switch to a lazy version (+? or *?) to stop at the shortest match. This is especially common when extracting content between HTML tags.

Test These Patterns in the Free Regex Tester →