🧩 JavaScript Regex Tester — Instant, Private, Client-Side
Test, debug, and save JavaScript regular expressions right in your browser — multi-tab editor, real-time highlights, and IndexedDB session saves. No servers. No tracking.
⚡ Why Choose Our Regex Tester?
- 🖥 Client-Side Only — All data stays in your browser (IndexedDB).
- 🗂 Multi-Tab Editor — Compare patterns and test strings side by side.
- 💾 Save & Load Sessions — Pick up where you left off anytime.
- 🔍 Instant Highlights — Matches and capture groups shown in real-time.
- 📜 Export JS Snippets — Copy tested regex directly into your code.
- 📚 Cheat Sheet & Examples — Common patterns ready to use.
🛠 Features
- Real-Time Matching: See matches and capture groups instantly.
- Quick Copy: Export patterns to JavaScript easily.
- Pattern Library: Preloaded examples for email, URL, phone, IP, and more.
- Private & Offline: No server required; fully offline-compatible.
- User-Friendly UI: Lightweight, responsive, multi-tab interface for devs.
🧰 Quick Cheat Sheet — How & When to Use It
Regular expressions can be intimidating at first. This cheat sheet breaks down flags, characters, classes, groups, and quantifiers and shows how and when to use them.
🔹 Flags (modifiers)
Flags modify the behavior of your regex. Always choose flags based on what you want to match.
| Flag | Use Case | Example |
|---|---|---|
g (global) |
Find all matches instead of stopping at the first | /d+/g matches all numbers in a string |
i (case-insensitive) |
Match letters ignoring case | /hello/i matches "hello" or "HELLO" |
m (multiline) |
^ and $ match start/end of each line, not just entire string |
/^abc/m finds lines starting with "abc" |
s (dotAll) |
. matches newline characters as well |
/a.b/s matches "a |
| b" | ||
u (unicode) |
Properly match unicode characters | /p{Emoji}/u matches emoji characters |
y (sticky) |
Match from the current index only | /abc/y matches at the exact position |
Tip: Use g when replacing or finding multiple matches. Use i for user input that may vary in case.
🔹 Special Characters
Special characters allow you to match characters literally or escape their special meaning.
| Character | How to Use | Example |
|---|---|---|
. |
Matches any character except newline | /a.b/ matches "acb" or "a_b" |
\ |
Escape a special character | /./ matches a literal dot "." |
* |
Matches 0 or more of previous character | /a*/ matches "", "a", "aa" |
+ |
Matches 1 or more of previous character | /a+/ matches "a", "aa" |
? |
Matches 0 or 1 of previous character | /colou?r/ matches "color" or "colour" |
Tip: Use `` when you want to match symbols like ., *, ?, +, (, ) literally.
🔹 Character Classes
Character classes match sets or ranges of characters.
| Class | How to Use | Example |
|---|---|---|
d |
Any digit | /d/ matches "1" |
w |
Any word character (letter, digit, underscore) | /w/ matches "a" or "9" |
s |
Any whitespace character | /s/ matches space, tab, newline |
D |
Any non-digit | /D/ matches letters |
W |
Any non-word character | /W/ matches "!" |
S |
Any non-whitespace | /S/ matches letters or numbers |
Tip: Use d for numbers, w for identifiers, and s to trim or detect spaces.
🔹 Groups & Captures
Groups let you capture parts of a match or apply quantifiers to multiple characters.
| Group | Use Case | Example |
|---|---|---|
() |
Capture group | /(d{3})-(d{2})/ captures "123" and "45" separately |
(?: ) |
Non-capturing | /(?:abc){2}/ repeats "abc" twice but doesn’t capture |
(?<name> ) |
Named capture group | /(?<year>d{4})-(?<month>d{2})/ |
Tip: Use capturing groups when you need to extract data, non-capturing to just group for repetition without storing matches.
🔹 Quantifiers
Quantifiers define how many times a pattern should repeat.
| Quantifier | Use Case | Example |
|---|---|---|
* |
0 or more | /a*/ matches "", "a", "aa" |
+ |
1 or more | /a+/ matches "a", "aa" |
? |
0 or 1 | /colou?r/ matches "color" or "colour" |
{n} |
Exactly n times | /d{3}/ matches "123" |
{n,} |
At least n times | /d{2,}/ matches "12", "123", "1234" |
{n,m} |
Between n and m times | /d{2,4}/ matches "12", "123", or "1234" |
Tip: Use {n,m} for flexible lengths, */+ for optional repeats, and ? for optional characters.
✅ How to Use Cheat Sheet Effectively
- Identify your need: What do you want to match? A number, email, URL, or custom string?
- Pick the right flags: Case-sensitive, global, or multiline?
- Use character classes:
dfor digits,wfor words,sfor spaces. - Group strategically: Capture what you need, repeat with non-capturing if needed.
- Test & refine: Use the Regex Tester live — tweak patterns and flags until your matches are correct.
- Export safely: Copy your tested regex into JS code for production.
Example:
- Want to validate a US phone number with optional country code:
/^+?1?s*(?d{3})?[-.s]?d{3}[-.s]?d{4}$/- Use
^&$to anchor the match,?for optional parts,dfor digits,sto allow spaces.
📋 Commonly Used Regex Patterns
| Pattern Name | Regex Example | Description | ||||
|---|---|---|---|---|---|---|
/^[^s@]+@[^s@]+.[^s@]+$/ |
Validates a standard email format | |||||
| URL (basic) | /^(https?://)?([w-]+.)+[w-]{2,}(/S*)?$/ |
Checks for HTTP/HTTPS URLs | ||||
| IPv4 Address | `/^(25[0-5] | 2[0-4]d | 1?d?d)(.(25[0-5] | 2[0-4]d | 1?d?d)){3}$/` | Validates IPv4 addresses |
| US Phone | /^+?1?s*(?d{3})?[-.s]?d{3}[-.s]?d{4}$/ |
Matches standard US phone numbers | ||||
| Hex Color | `/^#?([A-Fa-f0-9]{6} | [A-Fa-f0-9]{3})$/` | Checks for hex color codes | |||
| Strong Password | /^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[W_]).{8,}$/ |
Requires 8+ chars, mix of letters, numbers & symbols | ||||
| Date (YYYY-MM-DD) | /^(d{4})-(d{2})-(d{2})$/ |
Matches dates in ISO format | ||||
| Only Digits | /^d+$/ |
Validates strings with only digits |
✅ Tip: You can click or copy these patterns directly into your regex tester for instant testing.
💡 How to Script Your Regex in JavaScript
Basic match:
const pattern = /^[^s@]+@[^s@]+.[^s@]+$/;
const text = "alice@example.com";
console.log(pattern.test(text)); // true/falseGet all matches with capture groups:
const re = /(d{4})-(d{2})-(d{2})/g;
const str = "2025-01-01 and 2024-12-31";
const matches = [...str.matchAll(re)];
matches.forEach(m => console.log(m[0], 'Year:', m[1]));Replace matches dynamically:
const re = /(w+)@example.com/gi;
const s = "Contact: alice@example.com, bob@example.com";
const res = s.replace(re, (match, name) => `${name}@company.com`);
console.log(res);Create regex safely from user input:
function escapeForRegExp(str) {
return str.replace(/[.*+?^${}()|[]\]/g, '\$&');
}
const userInput = "foo.bar";
const safeRe = new RegExp(escapeForRegExp(userInput), "gi");💾 Save Sessions in Browser (IndexedDB)
async function saveSession(session) {
const db = await openDB('regex-tester', 1);
const tx = db.transaction('sessions','readwrite');
tx.objectStore('sessions').put(session);
return tx.complete;
}
saveSession({
id: 'session-1',
created: Date.now(),
tabs: [{ title:'Example', pattern:'/a/g', text:'abc' }]
});✅ Fully client-side, private, and offline.
❓ Frequently Asked Questions (FAQ)
Q1: Which regex flavor is supported?
- Our tester supports JavaScript (ES2018+) regex only. Other flavors like PCRE or Python are not supported yet.
Q2: How is my data saved?
- All sessions are stored in IndexedDB in your browser. Nothing is sent to our servers — your data remains private.
Q3: Can I use multiple tabs?
- ✅ Yes! You can create and switch between multiple tabs for different patterns and test strings.
Q4: How do I export a regex to my code?
- Click Export and copy the JavaScript snippet with your regex and flags, ready to use in your application.
Q5: Can I use it offline?
- Absolutely. Once the page is loaded, everything works offline, including session saving.
Q6: Are there ready-made patterns?
- Yes! We provide a pattern library with email, URL, phone, IP, hex colors, passwords, dates, and more.
🌟 Call-to-Action
-
[Try the Regex Tester Now]
-
[Load Example Patterns]
-
[Save Your Session]
- Client-side regex tester JavaScript
- Offline regex tester browser save sessions
- Multi-tab regex editor for developers