Regex Cheat Sheet
A searchable reference of regular-expression syntax, grouped by category. Filter live and copy any token with one click.
51
Tokens
7
Categories
51
Showing
Character classes
12.Any single character except a line break (unless the s flag is set).
Examplea.c matches abc, axc[abc]Any one of the listed characters (a, b, or c).
Example[aeiou] matches a single vowel[^abc]Any single character that is NOT one of the listed characters.
Example[^0-9] matches a non-digit[a-z]Any character in the given range (here, a lowercase letter).
Example[A-Fa-f0-9] matches a hex digit\dAny digit. Equivalent to [0-9].
Example\d\d matches 42\DAny non-digit character. Equivalent to [^0-9].
\wAny word character: a letter, digit, or underscore. Same as [A-Za-z0-9_].
Example\w+ matches snake_case_99\WAny non-word character. Equivalent to [^A-Za-z0-9_].
\sAny whitespace character: space, tab, newline, carriage return, form feed.
Example\s+ collapses runs of spaces\SAny non-whitespace character.
\.A literal dot. Backslash-escape any metacharacter to match it literally.
Example\d+\.\d+ matches 3.14\tA literal tab character. Likewise \n (newline) and \r (carriage return).
Anchors & boundaries
6^Start of the string (or start of a line with the m flag).
Example^Error matches lines beginning with Error$End of the string (or end of a line with the m flag).
Example\.csv$ matches a filename ending in .csv\bA word boundary: the position between a word and a non-word character.
Example\bcat\b matches cat but not category\BA non-word boundary: any position that is not a word boundary.
Example\Bend matches the end in weekend\AStart of the string only, never a line start (PCRE; not in JavaScript).
\zVery end of the string only (PCRE; not in JavaScript).
Quantifiers
8*Zero or more of the preceding token (greedy).
Exampleab*c matches ac, abc, abbbc+One or more of the preceding token (greedy).
Example\d+ matches one or more digits?Zero or one of the preceding token (makes it optional).
Examplecolou?r matches color and colour{n}Exactly n of the preceding token.
Example\d{4} matches a four-digit year{n,}At least n of the preceding token.
Example\d{2,} matches two or more digits{n,m}Between n and m of the preceding token, inclusive.
Examplea{1,3} matches a, aa, or aaa*?Lazy (non-greedy) match: as few repetitions as possible. Also +?, ??, {n,m}?.
Example<.*?> matches one tag, not the whole line*+Possessive match: like greedy but never backtracks (PCRE). Also ++, ?+.
Groups & alternation
6(abc)A capturing group; remembers the match for back-references and replacement.
Example(ab)+ matches abab and captures ab(?:abc)A non-capturing group: groups tokens without allocating a capture slot.
Example(?:https?)://(?<name>abc)A named capturing group, referenced later by its name.
Example(?<year>\d{4})-(?<month>\d{2})a|bAlternation: match the expression on the left OR the one on the right.
Examplecat|dog matches cat or dog\1A back-reference: matches the same text the first capturing group matched.
Example(['"]).*?\1 matches a quoted string\k<name>A back-reference to a named capturing group.
Example(?<q>['"]).*?\k<q>
Lookaround
4(?=abc)Positive lookahead: asserts what follows, without consuming it.
Example\d+(?= USD) matches digits before USD(?!abc)Negative lookahead: asserts that what follows is NOT the pattern.
Examplefoo(?!bar) matches foo not before bar(?<=abc)Positive lookbehind: asserts what precedes, without consuming it.
Example(?<=\$)\d+ matches digits after a $(?<!abc)Negative lookbehind: asserts that what precedes is NOT the pattern.
Example(?<!\d)\.\d+ matches a leading decimal
Flags & modifiers
7gGlobal: find all matches rather than stopping at the first.
Example/a/g replaces every aiCase-insensitive matching.
Example/error/i matches Error and ERRORmMultiline: ^ and $ match at the start and end of each line.
sDotall (single line): . also matches newline characters.
uUnicode: treat the pattern as a sequence of Unicode code points.
Example/\u{1F600}/u matches an emojiySticky: match only from the regex's lastIndex position (JavaScript).
(?i)Inline flag: enable case-insensitivity from this point on (PCRE).
Common patterns
8^[\w.+-]+@[\w-]+\.[\w.-]+$A pragmatic email address. Good enough for form validation, not RFC 5322.
Examplematches [email protected]^https?:\/\/[^\s/$.?#].[^\s]*$A http(s) URL, requiring a scheme and a non-empty host.
Examplematches https://example.com/path^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$An IPv4 address with each octet bounded to 0-255.
Examplematches 192.168.0.1^#?([\da-fA-F]{3}|[\da-fA-F]{6})$A 3- or 6-digit hexadecimal color, with an optional leading hash.
Examplematches #1a2b3c and fff^\d{4}-\d{2}-\d{2}$An ISO-8601 calendar date (YYYY-MM-DD).
Examplematches 2026-05-30^[a-z0-9]+(?:-[a-z0-9]+)*$A URL slug: lowercase words joined by single hyphens.
Examplematches my-blog-post^\+?[1-9]\d{7,14}$An E.164 international phone number (digits with an optional leading +).
Examplematches +14155552671[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}A UUID / GUID in its canonical 8-4-4-4-12 hyphenated form.
Examplematches 550e8400-e29b-41d4-a716-446655440000
About this cheat sheet
Tokens follow the PCRE and JavaScript (ECMAScript) flavors, which cover the vast majority of everyday matching. Engine-specific notes are called out in the explanations. The common patterns are practical, validation-grade starting points — not exhaustive specifications — so test them against your own data before shipping.