Regex Tester
Write and test regular expressions with live highlighting. See every match and capture group, try replacements, toggle flags and start from ready-made patterns like email, URL, mobile number and CNIC.
How to use the Regex Tester
- Type your pattern between the slashes, or pick a common pattern.
- Choose flags such as g (all matches) and i (ignore case).
- Paste your test text — matches are highlighted instantly.
- Check groups in Match details, or type a replacement to preview it.
Quick reference
- \d digit · \w letter, digit or _ · \s space · . any character
- + one or more · * zero or more · ? optional · {2,4} 2 to 4 times
- ^ start · $ end · \b word boundary
- ( ) group · (?<name> ) named group · [abc] one of a, b, c
Frequently asked questions
Which regex flavour is used?
JavaScript (ECMAScript), the same as in browsers and Node.js.
What do the flags mean?
g finds all matches, i ignores case, m makes ^ and $ work per line, s lets . match new lines, u enables Unicode.
How do I use groups in a replacement?
Use $1, $2 for numbered groups and $<name> for named groups.
Why does my pattern freeze?
Some patterns take very long on certain text. The tester stops after a short time to keep the page responsive.
Is there a pattern for Pakistani mobile numbers?
Yes — choose Pakistani mobile or CNIC from Common patterns.
Is my data sent anywhere?
No. Everything is calculated in your browser on your own device. Nothing you type or open is uploaded.
Patterns explained with examples
| Pattern | Matches | Note |
|---|---|---|
\d{4} | 2026 in “Year 2026” | \d is any digit |
colou?r | color and colour | ? makes the u optional |
^\s+|\s+$ | Spaces at the start or end | Use with the g flag to trim |
\.pdf$ | Names ending in .pdf | The dot must be escaped |
<.+?> | One HTML tag at a time | +? is lazy, it stops early |
Greedy and lazy
By default .+ takes as much text as it can. On <b>Hi</b>, the pattern <.+> matches the whole line, while <.+?> matches only <b>. Adding ? after + or * makes it lazy.
Common mistakes
- Forgetting to escape special characters like . ? + ( ) when you mean them literally.
- Leaving out the g flag and wondering why only the first match is replaced.
- Nested repeats like (a+)+ can make some regex engines run for a very long time on long text. Keep patterns simple.
This tester uses JavaScript regular expressions. Python, PHP and Java are very similar, but check small differences, such as named groups, before you copy a pattern into another language.