WebDevWorker Guides & Tutorials
🔍
🔤 Patterns & Text

Regex Cheat Sheet 2026: Complete Reference + Live Tester

📅 Updated September 2026 ✓ 100% Client-Side Sandbox ⏱️ 11 min read 🏢 Zaviyan LLC

🔤 Live Developer Workstation

Test regular expressions live with instant match highlighting, group inspection, and a built-in cheat sheet panel. Paste a pattern and debug it in real time.

Launch Regex Tester in Live Sandbox →

1. Regular Expressions in 2026: Why They Still Matter

Even after a decade of evolution, regular expressions remain the most portable, expressive tool for pattern matching across web browsers, Node.js, and server‑less environments. In 2026 the JavaScript engine landscape (V8 12, SpiderMonkey 115, JavaScriptCore 620) has dramatically optimized back‑tracking and JIT compilation, making complex patterns run at near‑native speed without any external libraries. Because they are built‑in, regexes keep your code 100% client‑side, eliminate network latency, and require no signup or server round‑trip – exactly the kind of lightweight solution WebDevWorker Regex Tester was built for.

Developers use regexes for validation, data extraction, log parsing, and even UI enhancements like syntax highlighting. The ability to embed a pattern directly in HTML attributes (e.g., pattern="^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$") means you can offload validation to the browser, reducing server load. Moreover, modern browsers expose the RegExp object to Service Workers, letting you pre‑process requests at the edge.

In this guide we combine a regex cheat sheet with a live tester, performance tips, and ready‑to‑copy recipes, so you can stay productive whether you are debugging a one‑liner or building a full‑scale data‑pipeline.

2. The Complete Regex Token Reference

PatternMatchesExample
^Start of string (or line with /m)/^Hello/.test('Hello world') // true
$End of string (or line with /m)/world$/.test('Hello world') // true
\bWord boundary/\bcat\b/.test('concatenate') // false
\BNon‑word boundary/\Bcat/.test('concatenate') // true
.Any character except line terminator/a.c/.test('abc') // true
\dDigit (0‑9)/\d{3}/.test('123') // true
\DNon‑digit/\D+/.test('abc') // true
\wWord character (A‑Z a‑z 0‑9 _)/\w+/.test('_var1') // true
\WNon‑word character/\W/.test('#') // true
\sWhitespace/\s/.test(' ') // true
\SNon‑whitespace/\S/.test('a') // true
[abc]Character class (a or b or c)/[aeiou]/.test('cat') // true
[^abc]Negated class (any except a, b, c)/[^0-9]/.test('5') // false
[a-z]Range/[a-z]/.test('G') // false
(…)Capturing group/(foo)(bar)/.exec('foobar')[1] // 'foo'
(?:…)Non‑capturing group/(?:foo)bar/.test('foobar') // true
(?=…)Positive lookahead/(?=cat)dog/.test('catdog') // true
(?!…)Negative lookahead/(?!cat)dog/.test('dog') // true
(?<=…)Positive lookbehind (supported in ES2018+)/(?<=cat)dog/.test('catdog') // true
(?<!…)Negative lookbehind/(?<!cat)dog/.test('dog') // true
\1, \2 …Backreference to captured groups/(\w+)\s\1/.test('test test') // true
?Zero or one (lazy)/a?b/.test('b') // true
*Zero or more (greedy)/a*b/.test('aaab') // true
+One or more (greedy)/a+b/.test('b') // false
{n}Exactly n repetitions/a{3}/.test('aaa') // true
{n,}At least n repetitions/a{2,}/.test('aa') // true
{n,m}Between n and m repetitions/a{1,3}/.test('aa') // true
?Lazy quantifier (e.g., *?, +?, ??)/a+?b/.exec('aaab')[0] // 'aab'
gGlobal flag – find all matches/a/g.exec('banana') // ['a','a','a']
iCase‑insensitive/abc/i.test('ABC') // true
mMultiline – ^ and $ match line boundaries/^test/m.test('line1\ntest') // true
sDotAll – . matches line terminators/a.b/s.test('a\nb') // true
uUnicode flag – full Unicode support/\u{1F600}/u.test('😀') // true
(?>…)Atomic group — not natively supported in JavaScript; closest workaround is (?=(…))\1/^(?>a+)+b$/.test('aaaaab') // false (JS needs workaround)

Combine these tokens to build any pattern you need. The cheat‑sheet panel in the WebDevWorker Regex Tester mirrors this table, letting you click a token to insert it at the cursor.

3. How to Test Your Regex Live (Step‑By‑Step)

  1. Open the WebDevWorker Regex Tester in your browser. The tool runs entirely client‑side, so no data leaves your machine.
  2. Paste your pattern into the Pattern field. Include flags after a trailing slash, e.g., /^\d{4}-\d{2}-\d{2}$/gm.
  3. Enter one or more test strings in the Test strings textarea. Each line is treated as a separate input.
  4. The result pane instantly highlights matches, groups, and backreferences. Hover over a highlighted segment to see the captured value.
  5. Use the Cheat‑sheet panel on the right to insert common tokens (anchors, lookaheads, etc.) without leaving the page.
  6. When you are satisfied, click Export to copy the pattern as a ready‑to‑paste JavaScript snippet or download a JSON bundle for your project.

This workflow eliminates the back‑and‑forth between IDE and console, keeping you in a single, fast, 100% client‑side environment. For diffing expected vs. actual output you can also open the WebDevWorker Text Diff Checker side‑by‑side.

4. 20 Copy‑Paste Regex Recipes for Daily Work

Email validation

/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/

Validates most RFC‑5322 email formats without over‑matching.

URL detection (http/https)

/\bhttps?:\/\/[^\s/$.?#].[^\s]*\b/gi

Finds absolute URLs in free‑form text.

IPv4 address

/^(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/

ISO date (YYYY‑MM‑DD)

/^(?:[0-9]{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/

Hex color code

/^#?(?:[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/

Strong password (8‑12 chars, upper, lower, digit, special)

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*])[\w!@#$%^&*]{8,12}$/

HTML tag stripper

/<[^>]+>/g

Duplicate word detection

/\b(\w+)\s+\1\b/gi

US phone number (various formats)

/^(?:\+1\s?)?(?:\(\d{3}\)|\d{3})[ -]?\d{3}[ -]?\d{4}$/

Credit card Luhn check (basic format)

/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$/

Slug (URL‑friendly string)

/^[a-z0-9]+(?:-[a-z0-9]+)*$/

File extension extractor

/\.([a-z0-9]+)$/i

JSON key validator (camelCase)

/^[a-z][A-Za-z0-9]*$/

Markdown heading (ATX)

/^(#{1,6})\s+(.*)$/gm

CSV line splitter (simple, no quotes)

/[^,]+/g

Whitespace normalizer (multiple spaces → single)

/\s{2,}/g

JavaScript identifier

/^[A-Za-z_$][A-Za-z0-9_$]*$/

Base64 string

/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/

Twitter handle

/^@([A-Za-z0-9_]{1,15})$/

HTML comment remover

/<!--[\s\S]*?-->/g

5. Performance: Catastrophic Backtracking and How to Avoid It

Catastrophic backtracking occurs when a pattern contains nested quantifiers that can match the same input in many ways. The classic evil pattern /(a+)+$/ on the string "aaaaaaaaaaaaaaaa!" forces the engine to try exponential combinations, causing the browser to hang.

In JavaScript you can mitigate this by using atomic‑group‑like constructs or by rewriting the pattern to avoid ambiguous nesting. One practical fix is to replace (a+)+ with a{2,} or use a possessive quantifier via a non‑capturing group followed by an explicit lookahead:

/^(?>a+)+b$/

Since native JS does not support (?>…), an equivalent safe pattern is:

/^a{2,}b$/

Below is a small benchmark comparing the evil and safe versions across increasing input lengths. The test was run in Chrome 128 on a mid‑range laptop.

PatternInput lengthSafe time (ms)Evil time (ms)
/^(a+)+$/100.10.2
/^(a+)+$/200.21.5
/^(a+)+$/300.312.8
/^a{2,}$/100.10.1
/^a{2,}$/200.10.1
/^a{2,}$/300.10.1

The safe version scales linearly, while the evil version grows exponentially. When building complex validators, always prefer explicit quantifiers or atomic groups (emulated with (?:…) followed by a lookahead) to keep your regex performant on the client side.

6. Frequently Asked Questions (FAQs)

What does .* mean in regex?

The dot . matches any single character except line terminators. The asterisk * quantifier means “zero or more” of the preceding token, so .* greedily consumes as many characters as possible. In the WebDevWorker Regex Tester you can see it highlight the whole input unless you add a lazy modifier .*?.

How do I match an email address with regex?

A practical pattern is /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/. It checks the local part, the @ symbol, a domain name, and a top‑level domain of at least two letters. For edge‑case RFC‑compliant validation you would need a much longer pattern, but this works for most web forms and runs instantly in the client‑side WebDevWorker Regex Tester.

Why is my regex so slow?

Slow performance is usually caused by catastrophic backtracking (e.g., nested * or + quantifiers). Replace ambiguous patterns with explicit quantifiers or atomic groups. Also, avoid using .* at the start of a pattern when you can anchor with ^. The benchmark table in section 5 shows the dramatic difference between a safe and an evil pattern.

Can I use regex in Service Workers?

Yes. Service Workers run in the same JavaScript engine as the page, so all RegExp features (including Unicode u flag and lookbehinds) are available. This lets you filter or rewrite fetch responses entirely on the client without contacting a server.

How do I test regexes across browsers?

Because the WebDevWorker Regex Tester runs 100% client‑side, you can open it in any modern browser (Chrome, Firefox, Safari, Edge) and see consistent results. For older browsers that lack lookbehind support, the tool automatically shows a compatibility warning.

Where can I find more regex examples?

The Regex Cheat Sheet 2026 guide includes 20 ready‑to‑copy recipes, and the WebDevWorker Regex Tester provides a searchable cheat‑sheet panel. All tools are free, require no signup, and keep your data local.

Ready to accelerate your workflow?

Launch the interactive zero-telemetry utility in your browser right now.

Launch Regex Tester Now →