// 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
| Token | Meaning | Example |
|---|---|---|
. | Any character except newline | a.c → abc |
\d | Any digit (0–9) | \d\d → 42 |
\D | Any non-digit | |
\w | Word character (a–z, A–Z, 0–9, _) | |
\W | Any non-word character | |
\s | Whitespace (space, tab, newline) | |
\S | Any 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
| Token | Meaning | Example |
|---|---|---|
^ | Start of string (or line, with m flag) | ^Hello |
$ | End of string (or line, with m flag) | world$ |
\b | Word boundary | \bcat\b |
\B | Not a word boundary |
Quantifiers
| Token | Meaning | Example |
|---|---|---|
* | 0 or more of the preceding token | a* |
+ | 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
| Token | Meaning | Example |
|---|---|---|
(abc) | Capturing group | (\d{4})-(\d{2}) |
(?:abc) | Non-capturing group | |
(?<name>abc) | Named capturing group | (?<year>\d{4}) |
\1 | Backreference to group 1 | (\w)\1 |
\k<name> | Named backreference | |
a|b | Match a or b (alternation) | cat|dog |
Lookaround
| Token | Meaning | Example |
|---|---|---|
(?=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)
| Token | Meaning | Example |
|---|---|---|
g | Global — find all matches, not just the first | /a/g |
i | Case-insensitive matching | /hello/i |
m | Multiline — ^ and $ match at line breaks | |
s | Dotall — . also matches newlines | |
u | Unicode mode | |
y | Sticky — match from lastIndex only |
Escapes & special characters
| Token | Meaning | Example |
|---|---|---|
\. | A literal dot (escape a metacharacter) | 3\.14 |
\\ | A literal backslash | |
\n \t \r | Newline, tab, carriage return | |
\uXXXX | Unicode code point (hex) | \u00e9 → é |
\xXX | Character by two-digit hex code | \x41 → A |
Ready-to-use patterns
| Token | Meaning | Example |
|---|---|---|
[^\s@]+@[^\s@]+\.[^\s@]+ | Email address (simple) | |
https?:\/\/[^\s]+ | HTTP / HTTPS URL | |
\b(?:\d{1,3}\.){3}\d{1,3}\b | IPv4 address | |
#(?:[0-9a-fA-F]{3}){1,2}\b | Hex colour (#fff or #ffffff) | |
\d{4}-\d{2}-\d{2} | ISO date (YYYY-MM-DD) | |
^\s+|\s+$ | Leading / trailing whitespace (to trim) |
// related tools
Put this to work
// related guides
Go deeper
The Complete Guide to Regular Expressions Regex end to end — literals, metacharacters, character classes, quantifiers, anchors, groups, and flags — with focused deep-dives and a live tester. Regex Tester Regex Character Classes, Quantifiers & Anchors The core building blocks of every regex — character classes and shorthands, greedy vs lazy quantifiers, and the anchors that pin a match to a position. Regex Tester Regex Groups, Backreferences & Lookarounds The advanced-but-everyday regex features — capturing and named groups, alternation, backreferences, and lookahead/lookbehind assertions. Regex Tester How to Test and Debug Regular Expressions A practical approach to writing and debugging regex — flags, capture groups, common tokens, and how to test a pattern against real text. Regex Tester
More developer references
Cheat sheets and lookups paired with 36+ free, private, browser-based tools.