About this tool
Write a regular expression and see every match highlighted in your text as you type, with the position and capture groups of each match. Toggle the g, i, m, s and u flags, test a replacement with $1 or named groups, or start from ready patterns for email addresses, URLs, dates and Pakistani or UAE mobile numbers. Everything runs in your browser, and slow patterns are stopped automatically instead of freezing the page.
How to use it
- Type your pattern without the surrounding slashes, or pick a common pattern to start from.
- Choose the flags you need — g to find every match, i to ignore case, m for line-by-line ^ and $.
- Paste your test text and read the highlighted matches and groups; tick “Also test a replacement” to preview a replace.
Good to know
- Uses JavaScript (ECMAScript) regular expressions — the same engine as Node.js and every browser.
- Without the g flag only the first match is found, exactly as in JavaScript's exec().
- In replacements, $1, $2… insert numbered groups, $<name> inserts a named group and $& inserts the whole match.
- Matching runs in a background worker and stops after 1.5 seconds, so a pattern with catastrophic backtracking can't hang the page.
- “Extract matches” copies every match — or just one capture group — as a list, one per line, with an option to remove repeats.
- The list shows up to 1,000 matches; nothing you type is sent anywhere.
Regex basics in one minute
\d matches a digit, \w a letter, digit or underscore, \s a space, and . any character. + means one or more, * zero or more, ? optional and {3} exactly three. [abc] matches one of a, b or c, ^ and $ mark the start and end, and ( ) captures a group you can reuse in a replacement.
So \d{4}-\d{2}-\d{2} matches a date like 2026-11-13, and ^03\d{9}$ matches an 11-digit Pakistani mobile number written as 03001234567.
Worked example: reformatting dates
Pattern (\d{4})-(\d{2})-(\d{2}) with the g flag finds every YYYY-MM-DD date. With the replacement $3/$2/$1, the text “Due 2026-12-01” becomes “Due 01/12/2026”. With named groups — (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}) — the replacement $<d>/$<m>/$<y> does the same and is easier to read later.
Common mistakes
Forgetting the g flag and wondering why only one match appears. Forgetting to escape special characters — a literal dot is \., a literal + is \+. Using greedy .* where a lazy .*? is needed, so one match swallows the whole line. And nesting quantifiers such as (\w+)+, which can make matching extremely slow; this tester stops such patterns after 1.5 seconds.
Validating a list of emails or phone numbers? Clean it first with the Remove Duplicate Lines tool, then test your pattern on what is left.
Frequently asked questions
How do I test a regular expression?
Type the pattern, choose flags and paste sample text. Matches are highlighted instantly, and the table lists each match with its position and capture groups.
Why does my regex only find one match?
The g (global) flag is off. Without it JavaScript stops at the first match — turn on g to find them all.
What do the m and s flags do?
m makes ^ and $ match at the start and end of every line instead of the whole text. s lets the dot (.) match new-line characters too.
Why did my pattern stop with a “too slow” message?
Patterns with nested quantifiers, such as (a+)+ or (.*)*, can take exponential time on some text. Make the inner part more specific or remove the nesting.
Will a regex from here work in Python or PHP?
Mostly. Basic syntax is shared, but named groups, lookbehind and some flags are written differently. PHP's preg functions use PCRE and Python uses its re module — test there before relying on edge cases.