Regex cheatsheet with a live JavaScript pattern tester

Search 57 regular-expression tokens, flags and ready patterns, and try a pattern on your own text right above the table, using the same JavaScript regex engine your code will use.

Live demo · real result from this tool
Matches2
Capture groups
0
Flags
g

Matches

#IndexMatch
15555-0142
217555-0199

Highlighted

Showing57 of 57 entries

Table

TokenMeaningExampleGroup
.Any character except a newline (with the s flag, any character)a.c matches abc, a-cCharacters
\dA digit 0–9\d{4} matches 2026Characters
\DNot a digitCharacters
\wWord character: letter, digit or _\w+ matches user_1Characters
\WNot a word characterCharacters
\sWhitespace (space, tab, newline…)a\sb matches a bCharacters
\SNot whitespaceCharacters
\t \n \rTab, newline, carriage returnCharacters
\uFFFFA character by code unit\u00e9 matches éCharacters
\u{1F600}A code point (needs the u flag)Characters
\p{L}Unicode property: any letter (u flag)\p{L}+ matches caféCharacters
\p{Emoji}Unicode property: emoji (u flag)Characters
\.Escape a special character to match it literally\.comCharacters
[abc]One of the listed characters[aeiou]Classes
[^abc]Any character except those listed[^0-9]Classes
[a-z]A range[A-Za-z0-9]Classes
^Start of the text (each line with m)^HelloAnchors
$End of the text (each line with m)end$Anchors
\bWord boundary\bcat\b matches cat, not concatAnchors
\BNot a word boundaryAnchors
*0 or moreab*c matches ac, abbcQuantifiers
+1 or more\d+Quantifiers
?0 or 1 (optional)colou?rQuantifiers
{n}Exactly n\d{3}Quantifiers
{n,}n or more\w{8,}Quantifiers
{n,m}Between n and m\d{2,4}Quantifiers
*? +? ??Lazy: as few as possible<.+?> matches <b> not <b>…</b>Quantifiers
(…)Capturing group(\d{4})-(\d{2})Groups
(?:…)Non-capturing group(?:https?|ftp)://Groups
(?<name>…)Named group(?<year>\d{4})Groups
\1Back-reference to group 1(\w)\1 matches ll in helloGroups
\k<name>Back-reference to a named groupGroups
a|bAlternation: a or bcat|dogGroups
(?=…)Lookahead: followed by\d+(?=px)Lookaround
(?!…)Negative lookahead: not followed byfoo(?!bar)Lookaround
(?<=…)Lookbehind: preceded by(?<=\$)\d+Lookaround
(?<!…)Negative lookbehind(?<!-)\d+Lookaround
gFlag: find all matches/a/gFlags
iFlag: ignore case/hello/iFlags
mFlag: ^ and $ match at line breaksFlags
sFlag: . matches newlinesFlags
uFlag: Unicode modeFlags
vFlag: Unicode sets (set operations in classes)[\p{L}--[a-z]]Flags
yFlag: sticky — match at lastIndex onlyFlags
dFlag: match indicesFlags
$1 $2Replacement: insert group 1, 2"2026-10-02".replace(/(\d+)-(\d+)-(\d+)/, "$3/$2/$1")Replace
$<name>Replacement: insert a named groupReplace
$&Replacement: the whole matchReplace
$$Replacement: a literal $Replace
^[^\s@]+@[^\s@]+\.[^\s@]+$Pattern: simple email shape checkname@example.comCommon patterns
^\d{4}-\d{2}-\d{2}$Pattern: ISO date2026-10-02Common patterns
^#?([0-9a-f]{3}|[0-9a-f]{6})$Pattern: hex colour (with i)#1e90ffCommon patterns
^https?://\S+$Pattern: http(s) URLhttps://example.comCommon patterns
^[a-z0-9]+(?:-[a-z0-9]+)*$Pattern: URL slugmy-post-titleCommon patterns
^\+?[1-9]\d{6,14}$Pattern: E.164 phone number+919876543210Common patterns
^(?=.*[A-Z])(?=.*\d).{8,}$Pattern: 8+ chars with an uppercase letter and a digitPassw0rdXCommon patterns
\s+$Pattern: trailing whitespaceCommon patterns

57 rows — scroll inside the table, or download the CSV.

Processed on your device — nothing is uploaded.

How to use the regex cheatsheet

  1. Type a word in Filter to search the table: a token name (lookahead), a group (flags, replace) or a goal (phone, email, date). Leave it empty to see all 57 entries.
  2. Put a pattern in Try a pattern. The default is \b\d{3}-\d{4}\b.
  3. Set Flags (up to 8 characters, any of d g i m s u v y).
  4. Paste sample input into Test text. The match table, capture groups and a highlighted copy of the text appear above the cheatsheet.

What it does and when to use it

Use it when you know roughly what you want but not the exact syntax, such as how to write a lookbehind or which replacement code inserts a named group. You can then prove the pattern on real data before it goes into code. The table has nine groups: characters, classes, anchors, quantifiers, groups, lookaround, flags, replacement codes ($1, $<name>, $&, $$) and eight common patterns (ISO date, hex colour, URL slug, E.164 phone number and more).

The live tester is deliberately small. For replace previews and a token-by-token explanation of your pattern, use the advanced regex tester. To put user input inside a pattern safely, escape it first with the regex escaper or the string escaper.

How it works

Your pattern is compiled with new RegExp(pattern, flags) in your browser. Unknown flags, repeated flags and the u + v combination are rejected with a clear message before compiling. With g or y, every match is listed (up to 1,000). Without them, only the first is. Each row shows the match index and every capture group. The filter keeps a cheatsheet row only when all your words appear in it. Nothing leaves your device.

Worked examples

A lookbehind that grabs amounts after a dollar sign. Pattern (?<=\$)\d+, flags g, text Total $45, tax $5:

Matches: 2
# | Index | Match
1 | 7 | 45
2 | 16 | 5

A back-reference pasted as a literal, /(\w)\1/g, on hello balloon finds doubled letters:

Matches: 3
Capture groups: 1
1 | 2 | ll | l
2 | 8 | ll | l
3 | 10 | oo | o

Filtering for lookbehind returns Showing: 2 of 57 entries: (?<=…) and its negative form (?<!…).

Limits and tips

  • Engine differences. Lookbehind and named groups work in current browsers and Node, but older engines may reject them.
  • Long input can freeze the page. The tester runs on the main thread, so a catastrophic pattern on a long text can lock the tab.
  • Anchors need m for lines. ^ and $ match the whole text’s start and end unless you add m.
  • Common patterns are starting points. They check the format, not meaning: ^\d{4}-\d{2}-\d{2}$ accepts 2026-13-45.

Frequently asked questions

Which regex flavour does this follow?
JavaScript (ECMAScript), because the tester runs your browser's own RegExp. Most tokens work the same in Python, PCRE, Java and .NET, but flags differ, and v (Unicode sets) and d (match indices) are JavaScript-only.
Can I paste a pattern written as /…/flags?
Yes. A pattern like /(\w)\1/g is split into the pattern and its flags. If you also type something in Flags, that box wins.
Why does my pattern only find one match?
Without the g flag JavaScript stops at the first match, and the tool says so ("Add the g flag to find every match"). The default Flags value is g.
Is the email pattern good enough to validate addresses?
No. It only checks the rough shape something@something.something. It accepts many invalid addresses and is not the full grammar in RFC 5322. The only real test is sending a confirmation email.
What does the warning about nested quantifiers mean?
Patterns such as (a+)+ can take exponential time on long input that almost matches. This is called catastrophic backtracking. The check is a heuristic, so it can miss risky patterns and flag safe ones.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close