AnsaTools
All Tools

© 2026 AnsaTools by AnsaSolutions

All processing happens in your browser. Your data never leaves your device.

BlogAboutContactPrivacy PolicyTerms of Service

Regex Cheat Sheet

Quick reference for regular expression syntax, flags, and common patterns

Character Classes

.Any character except newlinea.c → abc, aXc
\dDigit (0-9)\d{3} → 123
\DNon-digit\D → a, !
\wWord character (a-z, A-Z, 0-9, _)\w+ → hello_1
\WNon-word character\W → @, #
\sWhitespace (space, tab, newline)\s → ' '
\SNon-whitespace\S+ → hello
[abc]Character set — matches a, b, or c[aeiou] → vowels
[^abc]Negated set — NOT a, b, or c[^0-9] → non-digit
[a-z]Character range[A-Z] → uppercase

Anchors

^Start of string / line^Hello → starts with Hello
$End of string / lineworld$ → ends with world
\bWord boundary\bcat\b → 'cat' not 'catch'
\BNon-word boundary\Bcat → 'scat'

Quantifiers

*0 or moreab*c → ac, abc, abbc
+1 or moreab+c → abc, abbc
?0 or 1 (optional)colou?r → color, colour
{n}Exactly n times\d{4} → 2024
{n,}n or more times\d{2,} → 12, 123
{n,m}Between n and m times\d{2,4} → 12, 1234
*?Lazy 0 or more<.*?> → first tag only
+?Lazy 1 or more.+? → shortest match

Groups & Lookaround

(abc)Capturing group(\d+)-(\d+) → groups
(?:abc)Non-capturing group(?:http|https)://
(?=abc)Positive lookahead\d(?=px) → number before px
(?!abc)Negative lookahead\d(?!%) → digit not before %
(?<=abc)Positive lookbehind(?<=\$)\d+ → after $
(?<!abc)Negative lookbehind(?<!\d)px → px not after digit
|Alternation (OR)cat|dog → cat or dog

Flags

gGlobal — find all matches/cat/g → all 'cat'
iCase-insensitive/hello/i → Hello, HELLO
mMultiline — ^ and $ per line/^start/m → each line
sDotall — . matches newline/a.b/s → a\nb
uUnicode support/\p{L}/u → letters

Common Patterns

^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$Email address[email protected]
^https?://[^\s]+$URLhttps://example.com
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$Hex color#FF5733 or #F53
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$IPv4 address192.168.1.1
^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)2024-01-31
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$Strong passwordAbc12345
Advertisement — Support free tools by whitelisting this site in your ad blocker.