Regex by Example
A one-page regex pocket reference. Every pattern tested.
The numbers

Six reference blocks, 13 tested recipes, and a gotchas section - grouped for scanning, not an alphabetical dump, so it fits on one page beside your editor.
13
tested recipes
1
page, print-ready
100%
patterns actually run
What's inside
- Anchors, character classes, quantifiers, groups, lookaround, and flags in one grid.
- Recipes for real tasks: dates, IPs, slugs, key=value pairs, duplicate lines.
- Honest gotchas: greedy matching, catastrophic backtracking, the email-regex myth.
- Print-quality vector PDF (A4), sharp at any zoom.
Everything included
- Anchors & boundaries: ^ - start of string (or line with m)
- Anchors & boundaries: $ - end of string (or line with m)
- Anchors & boundaries: \b / \B - word boundary / non-boundary
- Anchors & boundaries: \A \Z - start / end of whole string
- Character classes: . - any char except newline (see s flag)
- Character classes: \d / \D - digit / non-digit
- Character classes: \w / \W - word char [A-Za-z0-9_] / not
- Character classes: \s / \S - whitespace / non-whitespace
- Character classes: [aeiou] - any one listed char
- Character classes: [^0-9] - any char NOT listed
- Character classes: [a-f] - range a through f
- Quantifiers: * - 0 or more (greedy)
- Quantifiers: + - 1 or more
- Quantifiers: ? - 0 or 1 (optional)
- Quantifiers: {3} - exactly 3
- Quantifiers: {2,} - 2 or more
- Quantifiers: {2,4} - between 2 and 4
- Quantifiers: *? +? ?? - lazy: as few as possible
- Groups & alternation: (...) - capturing group
- Groups & alternation: (?:...) - non-capturing group
- Groups & alternation: (?P<y>...) - named group 'y' (Python)
- Groups & alternation: \1 - backreference to group 1
- Groups & alternation: a|b - match a or b
- Lookaround: (?=...) - lookahead, followed by
- Lookaround: (?!...) - negative lookahead, not followed by
- Lookaround: (?<=...) - lookbehind, preceded by
- Lookaround: (?<!...) - negative lookbehind, not preceded by
- Flags/modes: (?i) - ignore case (re.I)
- Flags/modes: (?m) - multiline: ^ and $ match each line (re.M)
- Flags/modes: (?s) - dotall: . matches newline (re.S)
- Flags/modes: (?x) - verbose: ignore whitespace (re.X)
- Recipe: Integer (signed) - [+-]?\d+, e.g. -42
- Recipe: Decimal number - [+-]?\d+(?:\.\d+)?, e.g. -3.14
- Recipe: Hex colour - #(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b, e.g. #1a2B3c
- Recipe: IPv4 (shape only) - \b(?:\d{1,3}\.){3}\d{1,3}\b, e.g. 10.0.0.1
- Recipe: ISO date - \b\d{4}-\d{2}-\d{2}\b, e.g. 2026-06-30
- Recipe: 24-hour time - \b([01]\d|2[0-3]):[0-5]\d\b, e.g. 23:59
- Recipe: URL slug - ^[a-z0-9]+(?:-[a-z0-9]+)*$, e.g. my-post-1
- Recipe: key=value pairs - (\w+)=([^;]+), e.g. a=1;b=2
- Recipe: Trim edge spaces - ^\s+|\s+$, e.g. " hi "
- Recipe: Blank line (m) - ^\s*$, e.g. a\n\nb
- Recipe: URL (pragmatic) - https?://[^\s/$.?#].[^\s]*, e.g. https://a.co/x
- Recipe: Email (pragmatic) - [^@\s]+@[^@\s]+\.[^@\s]+, e.g. a.b@x.co
- Recipe: Duplicate word - \b(\w+)\s+\1\b, e.g. "the the"
- Gotcha: Greedy by default - <.+> on <a><b> grabs the whole line; use lazy <.+?> to stop at the first >
- Gotcha: The dot skips newlines - . does not match a newline unless the (?s)/dotall flag is set
- Gotcha: Escape the metacharacters - backslash needed before . * + ? ( ) [ ] { } ^ $ | \ to match them literally
- Gotcha: Catastrophic backtracking - nested quantifiers on overlapping classes like (a+)+$ can hang on non-matching input; avoid ambiguous nesting, prefer possessive/atomic groups where available
- Gotcha: There is no perfect email regex - the address grammar is huge; the pragmatic pattern accepts almost all real addresses and a few invalid ones; validate by sending mail, not by regex
- Gotcha: Anchors and multiline - ^ and $ match string ends by default; add the (?m) flag to match at every line
- Notation is Python re / PCRE; flavours differ across engines, see your engine's docs
Frequently asked
Is this really free?
Yes. It's a free one-page pocket reference - nothing in the document itself gates any content behind payment; it's presented as a standalone give-away reference by Md Nasim Sheikh (www.nasimstg.dev).
What format is it in?
It's authored as LaTeX source (extarticle, A4 paper, two-column layout, no page numbering) built specifically to lay out as a single printable page - so the deliverable is a one-page PDF, not a multi-page ebook.
What regex flavor does it use, and will the patterns work in my language?
Patterns are written in Python/PCRE notation. The footer explicitly flags that "flavours differ" between engines and points you to your own engine's docs - so treat it as a Python/PCRE-accurate reference that's broadly, not universally, portable.
Is there a paid version with more recipes or explanations?
The document doesn't reference or link to any expanded or paid edition - it's scoped as a single self-contained pocket reference covering 6 syntax reference cards, 13 tested recipes, and 6 gotchas, with no upsell mentioned anywhere in the source.