toolwork.dev — software solutions

Text size14

Online regex cheat sheet

Quick online reference for regular expression syntax — character classes, quantifiers, anchors, groups, and copy-paste patterns with examples. Click any row to open the regex tester with that pattern pre-loaded.

Character classes

PatternMeaningExample
.Any character except newlinea.b → acb
\dDigit 0–9\d\d → 42
\DNon-digit\D+ → abc
\wWord character [A-Za-z0-9_]\w+ → hello_1
\WNon-word character\W → !
\sWhitespace (space, tab, newline)\s+ →
\SNon-whitespace\S+ → word
[abc]Any of a, b, or c[aeiou] → e
[^abc]Any character except a, b, or c[^0-9] → x
[a-z]Lowercase letter[a-z]+ → hello
[A-Z]Uppercase letter[A-Z]+ → HELLO
[0-9]Digit[0-9]{3} → 123

Anchors

PatternMeaningExample
^Start of string (or line with m flag)^Hello
$End of string (or line with m flag)end$
\bWord boundary\bcat\b → cat in the cat sat
\BNon-word boundary\Bcat → scat

Quantifiers

PatternMeaningExample
*Zero or moreab*c → ac, abc, abbc
+One or moreab+c → abc, abbc
?Zero or onecolou?r → color, colour
{3}Exactly 3 times\d{3} → 123
{3,}3 or more times\d{3,} → 1234
{3,5}Between 3 and 5 times\d{3,5} → 1234
*?Lazy zero or more<.*?>
+?Lazy one or more\d+?

Groups & alternation

PatternMeaningExample
(abc)Capturing group(\w+)@(\w+)
(?:abc)Non-capturing group(?:https?)://\w+
(?<name>abc)Named capturing group(?<user>\w+)
a|bAlternation — a or bcat|dog

Lookahead & lookbehind

PatternMeaningExample
(?=abc)Positive lookahead\w+(?=\s)
(?!abc)Negative lookahead\d+(?!px)
(?<=abc)Positive lookbehind(?<=\$)\d+
(?<!abc)Negative lookbehind(?<!\d)\w+

Common patterns

PatternMeaningExample
\b\w+@\w+\.\w+\bEmail address (simple)user@example.com
https?://[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=.]*URL (http/https)https://toolwork.dev
#[0-9a-fA-F]{3,8}\bHex color code#22d3ee
\b\d{1,3}(?:\.\d{1,3}){3}\bIPv4 address192.168.1.1
\b\d{4}-\d{2}-\d{2}\bISO date (YYYY-MM-DD)2026-06-10
\b[A-Z]{2,3}-\d{4,}\bTicket / reference IDTW-12345
(?<quote>['"])(?<value>(?:\\.|(?!\k<quote>).)*?)\k<quote>Quoted string (single or double)"hello world"
\/\*[\s\S]*?\*\/|\/\/.*$Block or line comment// comment

Flags reference

PatternMeaningExample
gGlobal — find all matches, not just the first
iIgnore case — A matches a
mMultiline — ^ and $ match line boundaries
sDotall — . matches newline characters
uUnicode — treat pattern as Unicode code points

Click any pattern to open the regex tester with that example pre-loaded.