Regex Cheatsheet

Complete regular expression reference with interactive live tester.

Matches will appear here...

Character Classes

PatternDescriptionExample
.Any character except newlinea.c → abc, a1c
\dDigit [0-9]\d+ → 123
\DNon-digit [^0-9]\D+ → abc
\wWord char [a-zA-Z0-9_]\w+ → hello_1
\WNon-word char\W → @, !
\sWhitespace [ \t\n\r\f]a\sb → a b
\SNon-whitespace\S+ → hello
[abc]Character set (a, b, or c)[aeiou] → vowels
[^abc]Negated set (not a, b, c)[^0-9] → non-digits
[a-z]Range (a to z)[A-Za-z]+ → words

Quantifiers

PatternDescriptionExample
*0 or more (greedy)ab*c → ac, abc, abbc
+1 or more (greedy)ab+c → abc, abbc
?0 or 1 (optional)colou?r → color, colour
{n}Exactly n times\d{3} → 123
{n,}n or more times\d{2,} → 12, 123, 1234
{n,m}Between n and m times\d{2,4} → 12, 123, 1234
*?0 or more (lazy)<.*?> → first tag only
+?1 or more (lazy)".+?" → first quoted

Anchors & Boundaries

PatternDescriptionExample
^Start of string/line^Hello → starts with Hello
$End of string/lineworld$ → ends with world
\bWord boundary\bcat\b → cat (not cats)
\BNon-word boundary\Bcat → scat, bobcat

Groups & Lookaround

PatternDescriptionExample
(abc)Capturing group(ab)+ → ab, abab
(?:abc)Non-capturing group(?:ab)+ → no capture
(?<name>)Named group(?<year>\d{4})
\1Backreference to group 1(\w+)\s\1 → the the
a|bAlternation (a or b)cat|dog → cat or dog
(?=abc)Positive lookahead\d(?=px) → 5 in 5px
(?!abc)Negative lookahead\d(?!px) → 5 in 5em
(?<=abc)Positive lookbehind(?<=\$)\d+ → 50 in $50
(?<!abc)Negative lookbehind(?<!\$)\d+ → non-price

Common Patterns

Use CasePatternNotes
Email[\w.-]+@[\w.-]+\.\w{2,}Basic email match
URLhttps?://[\w.-]+(?:/\S*)?HTTP/HTTPS URLs
IPv4\d{1,3}(?:\.\d{1,3}){3}Basic IP address
Phone\+?[\d\s()-]{7,15}International format
Hex Color#(?:[0-9a-fA-F]{3}){1,2}#fff or #ffffff
Date\d{4}-\d{2}-\d{2}YYYY-MM-DD format

Regex API

Test regex patterns programmatically:

curl "https://ai.doxx.lat/api/regex?pattern=\d%2B&test=hello123world"

Free API. No signup. CORS enabled.