DevLab
.*
Regex⭐ Popularbeginner

Regex Cheatsheet

browse a complete regex syntax reference with live examples

By Bikram NathLast updated

A searchable reference for every regex syntax element: metacharacters, quantifiers, groups, and assertions, all with live examples you can filter instantly. Useful when you half-remember whether \b matches inside a word or at its edge — type 'boundary' and the answer surfaces immediately. Unlike regex101, this is a reference not a tester, so the focus is on syntax lookup rather than match debugging.

In development

Interactive Regex Cheatsheet — coming soon

We're still building the interactive Regex Cheatsheet. The guide below explains exactly what it does and how to use it. In the meantime, here are DevLab tools that already work in your browser:

Browse all working tools →

What is Regex Cheatsheet?

Regex Cheatsheet is a filterable syntax reference covering the full range of regular expression constructs: literals, metacharacters like \d and \s, quantifiers like {n,m} and ?, anchors like ^ and $, capturing and non-capturing groups, named captures, lookaheads, lookbehinds, and Unicode property escapes. Each entry includes a short example showing input and what it matches, so you can verify your mental model without switching tools. Typing 'lazy' immediately narrows the list to \*? and +? with examples showing how they differ from greedy variants.

Developers typically reach for this when they remember a pattern works but can't recall the exact syntax, or when learning an unfamiliar construct like possessive quantifiers or atomic groups. It fills a different role than regex101 or regexr, both of which center on testing a specific pattern against input text. Those tools are better for iterating on a regex you're actively writing; this one is better for the 'what's the syntax for named backreferences again?' moment.

One thing that trips people up: the cheatsheet reflects ECMAScript regex syntax by default, which supports named captures (?<name>...) and lookbehinds only from ES2018 onward. If you're writing patterns for a non-JS engine like PCRE or Python's re module, some syntax will differ. PCRE supports possessive quantifiers (\d++) and atomic groups ((?>...)) which ECMAScript does not, so a pattern that looks valid here may fail or behave differently in PHP or Perl.

When to use Regex Cheatsheet

Confirm whether a quantifier is greedy or lazy before pasting a pattern into production code.
Look up Unicode property escape syntax like \p{Letter} when writing internationalization-aware validation.
Distinguish named capture group syntax between ECMAScript, Python, and PCRE before porting a regex across languages.

Expert Notes

Most developers memorize about 20% of regex syntax and look up the rest. The cheatsheet exists for that 80%. The biggest practical gap I see is around Unicode-aware patterns — developers write \w expecting it to match accented characters (it doesn't in ECMAScript; \w is ASCII-only), then get bug reports from users with names like José or Müller. The Unicode property escapes (\p{Letter}, \p{Script=Greek}) solve this cleanly but are still underused because they feel unfamiliar. If you're building anything that touches user-generated text from a multilingual audience, learn \p{} syntax before you need it in a production incident.

DevLab's Take

This is the page I keep open in a pinned tab during code review. It's faster than regex101 when you just need to confirm syntax — you're not building a pattern, you're verifying one. The filter narrows 100+ entries to the one you need in under a second. The main limitation is that it's ECMAScript-focused, so if you're switching between Python and JavaScript regex (which happens constantly in data engineering), you'll still need to double-check engine-specific differences like named group syntax and flag behavior.

Frequently Asked Questions

Does this cheatsheet cover Python regex syntax or only JavaScript?
The examples and syntax shown follow ECMAScript (JavaScript) regex conventions. Most constructs overlap with Python's re module, but there are meaningful differences. Python uses (?P<name>...) for named captures while ECMAScript uses (?<name>...). Python's re module does not support \d matching Unicode digits by default unless you use the re.UNICODE flag, whereas ECMAScript's \d matches only ASCII digits 0-9 regardless. If you're writing Python regex, treat this as a starting reference and verify engine-specific behavior against the Python docs or a PCRE-targeted tool.
What's the difference between a non-capturing group (?:...) and a lookahead (?=...)?
A non-capturing group (?:...) matches and consumes the characters inside it, grouping them for quantifiers or alternation without creating a numbered capture. A lookahead (?=...) asserts that something follows the current position but does not consume any characters, so the regex engine's position doesn't advance past it. The practical consequence: 'colou?r' and '(?:colou?)r' behave the same for matching, but '(?=colou?r)' only checks that the position is followed by that pattern without including it in the overall match.
Why does \s match more than just spaces and tabs?
In ECMAScript, \s matches the full Unicode whitespace category: space (U+0020), tab (\t), newline (\n), carriage return (\r), form feed (\f), vertical tab (\v), non-breaking space (U+00A0), and a handful of other Unicode space separators including the zero-width no-break space (U+FEFF). This bites developers who assume \s is equivalent to [ \t] and then encounter form input containing a non-breaking space pasted from a Word document. If you need to match only ASCII whitespace, use [ \t\n\r\f\v] explicitly.
Do lookbehinds work in all browsers today?
Lookbehinds (both fixed-length (?<=...) and variable-length (?<!...)) were added to ECMAScript in ES2018. They are supported in V8 (Chrome, Edge, Node.js) and SpiderMonkey (Firefox) since mid-2018. Safari added support in Safari 16.4, released March 2023. If your app targets Safari versions before 16.4 or older WebViews, lookbehinds will throw a SyntaxError at runtime. For environments where support is uncertain, a capturing group with post-match index arithmetic is the fallback pattern.
What's the difference between \b and \B in practice?
\b is a zero-width assertion that matches at a position between a word character (\w, meaning [a-zA-Z0-9_]) and a non-word character or string boundary. \B is its inverse: it matches at any position where \b does not. So \bcat\b matches 'cat' in 'the cat sat' but not in 'concatenate', while \Bcat\B matches the 'cat' inside 'concatenate' but not the standalone word. The common confusion is that \b is not about spaces; it's about the transition between \w and \W characters, so 'cat!' has a \b between 't' and '!'.

Related Tools

Learn more