godz.online
Back to tools

TLDR reference

Regex cheatsheet

A searchable reference for regular-expression syntax, each token with its meaning and an example. Type to search by symbol or description, or filter by group. Everything runs in your browser.

38 shown

How it works

A searchable cheatsheet for regular expressions, with every token paired with a plain-language meaning and a small example. Regex packs a lot of power into a few symbols, and the hard part is remembering which symbol does what: this groups them the way you think about them - anchors, character classes, quantifiers, groups and lookaround, flags, and escapes - so you can find the piece you need without scrolling a wall of syntax. Type to search by symbol or by description, such as "word boundary" or "lazy".

The syntax follows the JavaScript flavour (the same engine behind the regex tester on this site), which is close to what PCRE, Python, and most other languages use day to day. Each card shows the token, what it matches, and an example so an abstract symbol like \b or (?=...) becomes concrete. Everything is static and runs in your browser, so the lookup is instant and works offline once the page has loaded.

Example. Searching "repeat" surfaces the quantifiers together: + means one or more, * means zero or more, ? makes the preceding token optional, and {2,4} matches between two and four times. Filtering by the Groups & lookaround chip lines up (?:...) non-capturing groups next to (?=...) lookahead and (?<!...) negative lookbehind so you can see how they differ.

FAQ

What is the difference between greedy and lazy quantifiers?

By default quantifiers are greedy: they match as much text as they can and then give characters back only if the rest of the pattern fails. Adding a ? after a quantifier makes it lazy, so it matches as little as possible and expands only when forced to. On the string <a><b>, the greedy pattern <.*> matches the whole thing in one go, while the lazy <.*?> matches just <a>. Lazy quantifiers are the usual fix when a pattern is grabbing more than you intended.

What does a word boundary (\b) actually match?

A word boundary is a zero-width assertion: it matches the empty position between a word character (a letter, digit, or underscore) and a non-word character, or at the start or end of the string. It does not consume any characters; it just anchors the match. That is what lets \bcat\b match the word "cat" but not the "cat" inside "category" or "concatenate", because in those words the boundary on at least one side is missing.

What is the difference between a capturing and a non-capturing group?

Plain parentheses (...) do two jobs at once: they group part of the pattern so a quantifier or alternation applies to the whole thing, and they capture the matched text so you can reuse it via a backreference or in a replacement. When you only need the grouping and not the captured value, use a non-capturing group (?:...). It groups without numbering, which keeps your capture groups uncluttered and is slightly faster. Named groups (?<name>...) capture too, but let you refer to the result by name instead of by number.

How do I match a literal special character like a dot or a slash?

Escape it with a backslash. A bare dot . matches any character, so to match a real full stop you write \. - likewise \* for a literal asterisk, \( for a literal opening bracket, and \\ for a literal backslash. Inside a character class many of these lose their special meaning, so [.] also matches a literal dot. When in doubt, escaping a punctuation character is harmless, so reaching for the backslash is a safe habit.