Code Tools StudioCode Tools Studio
All Tools
Tools
JSON FormatterCode MinifierRegex TesterPDF MergePDF SplitPDF to TextImage ConverterJSON Schema GeneratorText Case ConverterBase64 Encoder/DecoderURL Encoder/DecoderHash GeneratorUUID GeneratorColor ConverterTimestamp ConverterLorem Ipsum GeneratorJWT DecoderText Diff CheckerMarkdown Previewer

Command Palette

Search tools and actions

Reference

The Regex Cheat Sheet: Every Symbol You Actually Need

Code Tools Studio·6 min read·March 31, 2026

Regex syntax is dense but small: most of what you'll ever need fits in the table below. Paste any of these straight into the Regex Tester against your own test string to see exactly what matches, live.

Character classes

  • . — any character except a newline
  • \d — a digit (0-9); \D — anything that isn't a digit
  • \w — a word character (letters, digits, underscore); \W — the opposite
  • \s — whitespace (space, tab, newline); \S — the opposite
  • [abc] — any one of a, b, or c; [^abc] — any character except those
  • [a-z0-9] — a range: any lowercase letter or digit

Quantifiers

  • * — zero or more
  • + — one or more
  • ? — zero or one (also marks a quantifier as "lazy" when placed after another quantifier, e.g. .*?)
  • {3} — exactly 3; {2,4} — between 2 and 4; {2,} — 2 or more

Anchors

  • ^ — start of the string (or line, with the m flag)
  • $ — end of the string (or line, with the m flag)
  • \b — a word boundary; \B — not a word boundary

Groups and alternation

  • (abc) — a capturing group, referenceable later as $1 in a replacement
  • (?:abc) — a non-capturing group: groups for the | or a quantifier without creating a $1
  • (?<name>abc) — a named capturing group, referenced as $<name>
  • a|b — matches a or b

Lookahead and lookbehind

  • a(?=b) — matches a only if followed by b (positive lookahead)
  • a(?!b) — matches a only if not followed by b (negative lookahead)
  • (?<=b)a — matches a only if preceded by b (positive lookbehind)
  • (?<!b)a — matches a only if not preceded by b (negative lookbehind)

Escaping

To match a character that's otherwise special (. * + ? ^ $ ( ) [ ] { } | \), escape it with a backslash: \. matches a literal period.

Common patterns worth keeping around

  • Email (simple, practical): ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$
  • URL: ^https?:\/\/[\w.-]+\.[a-zA-Z]{2,}(\/\S*)?$
  • IPv4 address: ^(\d{1,3}\.){3}\d{1,3}$ (matches the shape; doesn't validate that each octet is ≤ 255)
  • ISO date (YYYY-MM-DD): ^\d{4}-\d{2}-\d{2}$
  • Digits only: ^\d+$

None of these are exhaustively "correct" for every edge case — email validation in particular has no perfect regex — but they're the practical, good-enough versions worth reaching for first. Test any of them (or your own) against real input in the Regex Tester, which also exports a working snippet in JavaScript, Python, Java, or PHP once you've got a pattern that matches what you need.

Code Tools Studio - 19 privacy-first tools for everyday developer tasks | Product Hunt
Files auto-deleted after 1 hour TLS 1.3 encrypted 99.9% uptime
PrivacyTermsBlog

© 2026 Code Tools Studio. All rights reserved.