Utility Empire

Regular Expression - Quick Reference

Tokens, groups, lookarounds and flags for writing and reading regular expressions in JavaScript and beyond. All rows are plain text - search to filter, click Copy to grab the pattern.

Reference rack
STATUSREADY
ROWS46
NETWORKLOCAL
MODEREFERENCE
Item / patternWhat it means / how to use it
.Any character except a line terminator (with the /s flag, includes newlines).
\d / \DAny digit / any non-digit.
\w / \WWord character [A-Za-z0-9_] / any non-word character.
\s / \SWhitespace (space, tab, newline) / any non-whitespace.
[abc]Character set - matches one of a, b, or c.
[a-z] / [^a-z]Range match / negated set (anything not a to z).
\t / \n / \rTab, newline, carriage return escapes.
\x41 / \u00A0Hex escape / Unicode escape (for example U+00A0 no-break space).
^Start of the string (or start of a line with the /m flag).
$End of the string (or end of a line with /m).
\b / \BWord boundary / not a word boundary.
(abc)Capturing group (numbered $1, $2...).
(?:abc)Non-capturing group - groups without storing the match.
(?<name>abc)Named group; readable as match.groups.name in JS.
abc|defAlternation - match abc or def.
a{2} / a{2,4} / a{2,}Exact, range, and open-ended quantifiers.
* / + / ?0-or-more / 1-or-more / 0-or-1; make lazy with *? +? ??.
(?>abc)Atomic group - no backtracking back into it.
(?=text)Positive lookahead - the following text must match.
(?!text)Negative lookahead - the following text must NOT match.
(?<=text)Positive lookbehind; JS supports fixed-width lookbehind.
(?<!text)Negative lookbehind.
/gGlobal flag - find all matches instead of stopping at the first.
/iCase-insensitive matching.
/mMultiline - ^ and $ now match at each line boundary.
/sDotAll - the dot matches newlines too.
/uUnicode mode - proper codepoint handling and \p{} support.
/ySticky - matches only at exactly lastIndex.
Email, simple[^\s@]+@[^\s@]+\.[^\s@]+ - a solid filter, not an RFC-compliant validator.
URL (http/https)https?://[\w-]+(\.[\w-]+)+\S* - quick link detection.
IPv4(\d{1,3}\.){3}\d{1,3} - match, then validate each octet as 0-255.
UUID[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} - add /i for upper case.
Hex color#([0-9a-f]{3}|[0-9a-f]{6})\b - with /i for uppercase letters.
US phone, loose\+?1?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} - lenient by design.
ISO 8601 date\d{4}-\d{2}-\d{2} - matches YYYY-MM-DD.
URL slug^[a-z0-9]+(?:-[a-z0-9]+)*$ - lowercase words joined by single hyphens.
Blank lines^\s*$ - with the /m flag to find every one.
regex.test(str)Boolean - does a match exist?
str.match(pattern)All matches with /g; otherwise first match plus groups.
str.matchAll(pattern)Iterator over every match including groups; requires the /g flag.
str.replace(pattern, repl)"$1" and named groups work inside the replacement; /g replaces all.
str.search(pattern)Index of the first match or -1.
str.split(pattern)Split the string at every regex boundary.
Escape metacharacters\. \* \+ \? \( \) \[ \] \{ \} \| \^ \$ \\ - backslash-escape any of them when matching literally.
Backreference"\1" or $1 reuse what the first capturing group matched.
Catastrophic backtracking(a+)+ and similar stacked quantifiers can freeze the engine on long inputs - avoid nested quantifiers.