Regex Cheat Sheet with Live Examples
Searchable regular expression cheat sheet: anchors, classes, quantifiers, groups, lookarounds, flags and replacements, each with a live example.
A compact regular-expression reference you can filter and test. Every entry has a short explanation and an example, and the result column is produced live by your browser's regex engine, so you see exactly what each example matches rather than what a static chart claims. Notes flag the places where JavaScript, Python, PHP (PCRE), Java and .NET differ — the usual source of patterns that work in one language and fail in another.
How to use this tool
- Pick a section such as Quantifiers or Lookahead & lookbehind, or leave it on Everything.
- Type in the search box to filter, for example "lazy", "named" or "boundary".
- Read the example and the live result for each token.
- Press Calculate. Try your own pattern and text in the boxes below the sheet to check an idea straight away.
Formula
Each example runs as new RegExp(pattern, flags + "g") against its sample text; replacement examples use text.replace(regex, replacement).
Entries marked "not available in JavaScript" (possessive quantifiers, atomic groups, \A and \z, POSIX classes, verbose mode, inline flags) exist in other engines but cannot be shown live in a browser. Calculation runs in a worker and stops after two seconds.
Example
In the Quantifiers section, the lazy example /<.+?>/ on "<b>bold</b>" returns two matches, "<b>" and "</b>", while the greedy <.+> would take the whole string. In the try-it box, \b\d{3}-\d{4}\b on "Call 555-1234 or 555-98765 today." finds 1 match, 555-1234 — the second number fails because the boundary \b cannot sit between two digits.
Frequently asked questions
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, {n,m}) take as much text as they can and give it back only when the rest of the pattern fails. Adding ? (*?, +?) makes them take as little as possible, which is what you usually want between delimiters like quotes or tags.
Why does my lookbehind work in JavaScript but fail in Python?
Python's re module requires every lookbehind to have a fixed length, so (?<=\$\d*) is rejected. JavaScript and .NET accept variable-length lookbehind.
Does \w match accented letters?
JavaScript \w mainly matches ASCII letters, digits and underscore. With both Unicode and ignore-case flags, characters folding to ASCII, such as K and ſ, also match. Use \p{L} with u for Unicode letters.
Which characters must be escaped?
Outside brackets: . * + ? ^ $ { } ( ) | [ ] and the backslash itself. Inside brackets only ], \, ^ at the start and - between characters are special.
Sources
Last updated: 2026-10-30