Back to Blog
Reference 2026-04-25

Regex Cheatsheet for 2026

Quick reference for regex patterns, flags, and tested examples.

Regex is the Swiss Army knife of string processing. The syntax is dense; this cheatsheet covers what you reach for daily.

Character Classes

PatternMatches

|---------|---------|

\ddigit \Dnon-digit \wword char (a-z, A-Z, 0-9, _) \Wnon-word \swhitespace \Snon-whitespace .any char (no newline by default) [abc]a, b, or c [^abc]anything except a, b, c [a-z]range

Quantifiers

PatternMeaning

|---------|---------|

*0 or more +1 or more ?0 or 1 {n}exactly n {n,}n or more {n,m}between n and m +?, *?non-greedy

Anchors

  • ^ — start of string (or line with m flag)
  • $ — end of string (or line with m flag)
  • \b — word boundary
  • \B — non-word boundary

Groups and References

  • (abc) — capture group
  • (?:abc) — non-capturing
  • (?abc) — named capture
  • \1 — backreference to group 1
  • \k — backreference to named group

Lookarounds

  • (?=foo) — positive lookahead
  • (?!foo) — negative lookahead
  • (?<=foo) — positive lookbehind
  • (? — negative lookbehind

Common Patterns

Email:        ^[\w.+-]+@[\w-]+\.[\w.-]+$

URL (basic): https?://[\w.-]+(?:/[\w./?=&%-]*)?

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

ISO date: ^\d{4}-\d{2}-\d{2}$

UUID v4: ^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$

Slug: ^[a-z0-9]+(?:-[a-z0-9]+)*$

Flags

FlagEffect

|------|--------|

gglobal icase-insensitive mmultiline sdotall uunicode vunicode set notation ysticky

Tips

  • Test patterns interactively before deploying.
  • Catastrophic backtracking is real: avoid (a+)+.
  • Email regex perfection is impossible; validate by sending a confirmation.

Try patterns interactively in the [Regex Tester](https://sdk.is/regex-tester).