Regex Tester
Test and debug regular expressions in real time. Highlights all matches, shows capture groups, and supports find-and-replace. Runs entirely in your browser.
Quick patterns
How to Use This Regex Tester
Enter a regular expression in the pattern field (without slashes) and toggle flags using the buttons on the right. Paste your test string and matching substrings are highlighted in real time. The Match Details panel shows every capture group and named group for each match.
Switch to the Find & Replace tab to perform substitutions. Use $1, $2 to reference capture groups, and $& for the full match. Replacements run against the JavaScript String.prototype.replace engine.
Regex flags
| Flag | Name | Effect |
|---|---|---|
| g | Global | Find all matches instead of stopping at the first one. |
| i | Case insensitive | Match upper and lower case letters interchangeably. hello matches Hello, HELLO, hElLo. |
| m | Multiline | ^ and $ match the start and end of each line, not just the whole string. |
| s | Dot-all | The . metacharacter matches newline characters (\n) as well. Without this flag, . skips newlines. |
| u | Unicode | Treat the pattern as a sequence of Unicode code points. Required for \p{} Unicode property escapes. |
| y | Sticky | Match only at lastIndex — like ^ anchored to a specific position. Used for incremental parsing. |
| d | Indices | Adds indices property to match result with start/end positions of each group (ES2022). |
Regex metacharacters cheatsheet
| Symbol | Meaning | Example |
|---|---|---|
| . | Any character except newline (add s flag for newline) | a.c → abc, a1c, a-c |
| \d | Digit [0-9] | \d+ → 42, 007 |
| \D | Non-digit | \D+ → abc, hello |
| \w | Word character [a-zA-Z0-9_] | \w+ → hello_world |
| \W | Non-word character | \W+ → !@#, spaces |
| \s | Whitespace (space, tab, newline) | \s+ → spaces between words |
| \S | Non-whitespace | \S+ → every word token |
| \b | Word boundary | \bword\b → matches 'word' not 'password' |
| ^ | Start of string (or line with m flag) | ^Hello → matches only if string starts with Hello |
| $ | End of string (or line with m flag) | end$ → matches only if string ends with end |
| [abc] | Character class — a, b, or c | [aeiou] → matches any vowel |
| [^abc] | Negated class — anything except a, b, c | [^0-9] → matches non-digits |
| [a-z] | Range — a through z | [A-Z0-9] → uppercase or digit |
| (abc) | Capturing group — capture abc as $1 | (\d{4}) → captures year |
| (?:abc) | Non-capturing group — group without capture | (?:https?://) |
| (?<name>abc) | Named capturing group — capture as groups.name | (?<year>\d{4}) |
| a|b | Alternation — a or b | cat|dog → matches cat or dog |
| a? | Zero or one of a | colou?r → colour or color |
| a* | Zero or more of a (greedy) | ab*c → ac, abc, abbc |
| a+ | One or more of a (greedy) | \d+ → one or more digits |
| a{3} | Exactly 3 of a | \d{4} → exactly 4 digits |
| a{2,5} | Between 2 and 5 of a | \d{2,4} → 2 to 4 digits |
| a*? | Non-greedy (lazy) zero or more | <.*?> → shortest tag match |
| (?=abc) | Positive lookahead — followed by abc | \d+(?= dollars) |
| (?!abc) | Negative lookahead — not followed by abc | \d+(?! km) |
| (?<=abc) | Positive lookbehind — preceded by abc | (?<=\$)\d+ |
| (?<!abc) | Negative lookbehind — not preceded by abc | (?<!\d)\d{3} |
Common regex patterns
| Use case | Pattern |
|---|---|
| Email address | [a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} |
| URL (http/https) | https?:\/\/[^\s/$.?#].[^\s]* |
| IPv4 address | \b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b |
| Date YYYY-MM-DD | \d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) |
| Time HH:MM:SS | ([01]\d|2[0-3]):[0-5]\d:[0-5]\d |
| UUID / GUID | [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} |
| Hex color (#FFF or #FFFFFF) | #(?:[0-9a-fA-F]{3}){1,2}\b |
| US phone number | \+?1?[\s.-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} |
| Positive integer | ^[1-9]\d*$ |
| Decimal number | ^-?\d+(\.\d+)?$ |
| Slug (URL-safe) | ^[a-z0-9]+(?:-[a-z0-9]+)*$ |
| HTML tag | <([a-z][a-z0-9]*)(?:[^>]*)?>.*?<\/\1> |
| JSON string value | "(?:[^"\\]|\\.)*" |
| Semver | ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[\w.-]+)?(?:\+[\w.-]+)?$ |
| Credit card (basic) | \b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})\b |
Use regex in JavaScript
// Literal syntax
const re = /\d{4}-\d{2}-\d{2}/g;
// Constructor (for dynamic patterns)
const re = new RegExp('\\d{4}-\\d{2}-\\d{2}', 'g');
// Test: returns boolean
re.test('2024-04-18'); // true
// Match: returns array or null
'2024-04-18'.match(re); // ['2024-04-18']
// Match all (g flag): returns all matches
[...'2024-01-01 to 2024-12-31'.matchAll(re)].map(m => m[0]);
// Replace
'hello world'.replace(/\bworld\b/, 'there'); // 'hello there'
// Named groups
const { year, month, day } = '2024-04-18'.match(
/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/
).groups;Frequently asked questions
What is the difference between greedy and lazy quantifiers?▾
Greedy quantifiers (*, +, ?, {n,m}) match as much as possible. Lazy/non-greedy versions (*?, +?, ??, {n,m}?) match as little as possible. Example: given <b>bold</b><i>italic</i>, the pattern <.*> matches the entire string (greedy), while <.*?> matches just <b> (lazy).
What is a capturing group vs a non-capturing group?▾
(abc) is a capturing group — it captures the matched text and makes it available as $1, $2, etc. in replacements and as groups[0] in match results. (?:abc) is non-capturing — it groups without capturing, useful for applying quantifiers without cluttering the capture group list.
What is a lookahead and a lookbehind?▾
Lookaheads and lookbehinds are zero-width assertions — they match a position without consuming characters. Positive lookahead (?=abc) asserts that what follows is abc. Negative lookahead (?!abc) asserts it is not. Similarly for lookbehinds: (?<=abc) and (?<!abc). Example: \d+(?= dollars) matches a number only when followed by ' dollars'.
Why does my regex match too much or too little?▾
Too much: quantifiers are greedy — use lazy versions (*?, +?) or anchor with ^ and $. Too little: you may be missing the g flag (global), so only the first match is returned. The . doesn't match newlines by default — add the s flag. Character classes [^x] may exclude more than intended.
How do I test a regex against multiple lines?▾
Add the m (multiline) flag so ^ and $ match line boundaries. Add the g flag to find all matches. If you want . to match newlines too, add the s (dot-all) flag. In the tester, paste a multi-line string and enable the m and g flags.
How do I match a literal special character like . or *?▾
Escape it with a backslash: \. matches a literal dot, \* matches a literal asterisk, \( matches a literal opening parenthesis. Special characters that need escaping in regex: . * + ? ^ $ { } [ ] | ( ) /
Related Tools
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.