Dev Tools

Regex Cheatsheet

Interactive regex reference with searchable patterns, character classes, quantifiers, and examples.

41 results
PatternDescriptionExampleCategory
.Any character except newlinea.c matches "abc"Character Classes
\dDigit (0-9)\d+ matches "123"Character Classes
\DNon-digit\D+ matches "abc"Character Classes
\wWord character (a-z, A-Z, 0-9, _)\w+ matches "hello_1"Character Classes
\WNon-word character\W matches "@"Character Classes
\sWhitespace (space, tab, newline)a\sb matches "a b"Character Classes
\SNon-whitespace\S+ matches "hello"Character Classes
[abc]Character set: a, b, or c[aeiou] matches vowelsCharacter Classes
[^abc]Negated set: not a, b, or c[^0-9] matches non-digitsCharacter Classes
[a-z]Range: a through z[A-Za-z] matches lettersCharacter Classes
*Zero or moreab*c matches "ac", "abc", "abbc"Quantifiers
+One or moreab+c matches "abc", "abbc"Quantifiers
?Zero or one (optional)colou?r matches "color", "colour"Quantifiers
{n}Exactly n times\d{3} matches "123"Quantifiers
{n,}n or more times\d{2,} matches "12", "123"Quantifiers
{n,m}Between n and m times\d{2,4} matches "12", "1234"Quantifiers
*?Lazy zero or more<.*?> matches first tag onlyQuantifiers
+?Lazy one or more".+?" matches first quoted stringQuantifiers
^Start of string / line^Hello matches "Hello world"Anchors
$End of string / lineworld$ matches "Hello world"Anchors
\bWord boundary\bcat\b matches "cat" not "catch"Anchors
\BNon-word boundary\Bcat matches "concat"Anchors
(abc)Capturing group(\d+)-(\d+) captures both partsGroups & References
(?:abc)Non-capturing group(?:ab)+ matches "abab"Groups & References
(?<name>abc)Named capturing group(?<year>\d{4}) captures as "year"Groups & References
\1Back-reference to group 1(\w+)\s\1 matches "the the"Groups & References
(?=abc)Positive lookahead\d(?=px) matches "5" in "5px"Groups & References
(?!abc)Negative lookahead\d(?!px) matches "5" in "5em"Groups & References
(?<=abc)Positive lookbehind(?<=\$)\d+ matches "100" in "$100"Groups & References
(?<!abc)Negative lookbehind(?<!\$)\d+ matches "100" in "100"Groups & References
a|bAlternation: a or bcat|dog matches eitherAlternation & Flags
gFlag: global (find all matches)/\d+/g finds all numbersAlternation & Flags
iFlag: case-insensitive/hello/i matches "HELLO"Alternation & Flags
mFlag: multiline (^ and $ per line)/^start/m matches per lineAlternation & Flags
sFlag: dotAll (. matches newlines)/a.b/s matches "a\nb"Alternation & Flags
uFlag: Unicode mode/\p{L}/u matches Unicode lettersAlternation & Flags
^[\w.-]+@[\w.-]+\.\w{2,}$Email (simple)user@example.comCommon Patterns
^https?://[^\s]+$URL (simple)https://example.com/pathCommon Patterns
^\d{1,3}(\.\d{1,3}){3}$IPv4 address192.168.1.1Common Patterns
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$Hex color#ff0000 or #f00Common Patterns
^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)2024-01-15Common Patterns
Was this page helpful?

Related tools