Developer Tools
Regex Tester
Build and debug regular expressions with live match highlighting. See every match with its position and capture groups, try find-and-replace, and look up syntax in the cheat sheet below.
Test a Regular Expression
Enter a pattern without the surrounding slashes, choose flags and type your test text. Matches update as you type.
How to Use the Regex Tester
- Type your pattern in the regular expression box, without the opening and closing slashes.
- Tick the flags you need. The global flag
gfinds every match instead of only the first. - Enter the text to search. Matches are highlighted in alternating colours as you type.
- Check the table for the position of each match and the value of every capture group.
- To test a replacement, type it in the replace box. Use
$1,$2and so on to insert capture groups, and$&for the whole match.
The tester uses your browser's JavaScript regular expression engine, which matches the behaviour of JavaScript, TypeScript and Node.js. Most simple patterns work the same way in Python, PHP, Java and C#, but advanced features can differ.
Regex Cheat Sheet
| Pattern | Matches |
|---|---|
. | Any character except a line break (any character with the s flag) |
\d / \D | A digit 0–9 / anything that is not a digit |
\w / \W | A letter, digit or underscore / anything else |
\s / \S | Whitespace (space, tab, line break) / non-whitespace |
[abc] / [^abc] | Any one of a, b or c / any character except these |
[a-z0-9] | A character in a range |
^ / $ | Start / end of the text (or of each line with m) |
\b | A word boundary |
* / + / ? | 0 or more / 1 or more / 0 or 1 of the previous item |
{3} / {2,5} | Exactly 3 / between 2 and 5 times |
*? / +? | Lazy versions that match as little as possible |
(abc) | Capture group |
(?:abc) | Group without capturing |
(?<name>abc) | Named capture group |
a|b | a or b |
(?=abc) / (?!abc) | Followed by / not followed by abc (lookahead) |
\. \* \? | Escape special characters to match them literally |
Useful Patterns
| Purpose | Pattern |
|---|---|
| Simple email check | ^[^\s@]+@[^\s@]+\.[^\s@]+$ |
| Pakistani mobile number | ^(\+92|0092|0)3\d{2}-?\d{7}$ |
| Date as YYYY-MM-DD | ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ |
| URL starting with http or https | https?:\/\/[^\s]+ |
| Hex colour | ^#([0-9a-fA-F]{3}){1,2}$ |
| Extra spaces | {2,} |
| HTML tag | <[^>]+> |
Need a pattern quickly? The Regex Generator builds common expressions for you.
Tips for Writing Better Regex
- Anchor validation patterns with
^and$, otherwise "abc123xyz" passes a digits-only check because it contains digits. - Prefer specific classes such as
[^"]*over.*to avoid matching too much. - Avoid nested quantifiers such as
(a+)+, which can become extremely slow on long input (catastrophic backtracking). - Do not use regex to fully validate emails or parse HTML. Use a proper parser or library, and use regex for quick checks and extraction.
Privacy
Your pattern and test text are processed by your browser and never sent to a server.
Frequently Asked Questions
Which regex flavour does this tester use?
It uses the JavaScript (ECMAScript) regular expression engine built into your browser, the same as in Node.js and TypeScript. Most basic syntax is also valid in Python, PHP, Java and C#.
Why does my regex only find one match?
Tick the g (global) flag. Without it, JavaScript stops after the first match.
How do I see capture groups?
Wrap part of the pattern in parentheses. The table below the highlighted text shows each match with the value of every group.
How do I use capture groups in a replacement?
Type the replacement in the "Replace with" box and use $1, $2 and so on to insert groups, or $& for the entire match. Named groups can be inserted with $<name>.
What does the m (multiline) flag do?
It makes ^ and $ match at the start and end of every line instead of only the start and end of the whole text.
Why is my regex very slow?
Patterns with nested quantifiers such as (a+)+ or (.*)* can cause catastrophic backtracking. Make the pattern more specific or remove the nested repetition.