// reference

Regex Cheat Sheet

A quick reference for JavaScript regular expressions — character classes, quantifiers, anchors, groups, lookaround, flags and ready-to-use patterns.

Regular expressions look cryptic until the pieces are in front of you. This cheat sheet covers JavaScript regex syntax — the same flavour the DevUtilsNow regex tester uses — with a copyable example for the tokens you reach for most.

Character classes

TokenMeaningExample
.Any character except newlinea.c → abc
\dAny digit (0–9)\d\d → 42
\DAny non-digit
\wWord character (a–z, A–Z, 0–9, _)
\WAny non-word character
\sWhitespace (space, tab, newline)
\SAny non-whitespace character
[abc]Any one of a, b or c[aeiou]
[^abc]Anything except a, b or c
[a-z]Any character in the range a–z[a-zA-Z0-9]

Anchors & boundaries

TokenMeaningExample
^Start of string (or line, with m flag)^Hello
$End of string (or line, with m flag)world$
\bWord boundary\bcat\b
\BNot a word boundary

Quantifiers

TokenMeaningExample
*0 or more of the preceding tokena*
+1 or more\d+
?0 or 1 (makes it optional)colou?r
{n}Exactly n times\d{4}
{n,}n or more times\d{2,}
{n,m}Between n and m times\d{2,4}
*? +? ??Lazy — match as few as possible<.+?>

Groups, references & alternation

TokenMeaningExample
(abc)Capturing group(\d{4})-(\d{2})
(?:abc)Non-capturing group
(?<name>abc)Named capturing group(?<year>\d{4})
\1Backreference to group 1(\w)\1
\k<name>Named backreference
a|bMatch a or b (alternation)cat|dog

Lookaround

TokenMeaningExample
(?=abc)Positive lookahead — followed by abc\d(?=px)
(?!abc)Negative lookahead — not followed by abc
(?<=abc)Positive lookbehind — preceded by abc(?<=\$)\d+
(?<!abc)Negative lookbehind — not preceded by abc

Flags (JavaScript)

TokenMeaningExample
gGlobal — find all matches, not just the first/a/g
iCase-insensitive matching/hello/i
mMultiline — ^ and $ match at line breaks
sDotall — . also matches newlines
uUnicode mode
ySticky — match from lastIndex only

Escapes & special characters

TokenMeaningExample
\.A literal dot (escape a metacharacter)3\.14
\\A literal backslash
\n \t \rNewline, tab, carriage return
\uXXXXUnicode code point (hex)\u00e9 → é
\xXXCharacter by two-digit hex code\x41 → A

Ready-to-use patterns

TokenMeaningExample
[^\s@]+@[^\s@]+\.[^\s@]+Email address (simple)
https?:\/\/[^\s]+HTTP / HTTPS URL
\b(?:\d{1,3}\.){3}\d{1,3}\bIPv4 address
#(?:[0-9a-fA-F]{3}){1,2}\bHex colour (#fff or #ffffff)
\d{4}-\d{2}-\d{2}ISO date (YYYY-MM-DD)
^\s+|\s+$Leading / trailing whitespace (to trim)

More developer references

Cheat sheets and lookups paired with 36+ free, private, browser-based tools.

Browse references →
Last updated: Aug 18, 2026