Dev & Data
Regex tester
Type a pattern and some test text to see every match highlighted, with each capture group in a table. Try a replacement too. Your text never leaves this device.
- Free, no sign-up
- Runs in your browser
- Nothing uploaded
Pattern
Write the pattern without the slashes. /pattern/ pasted from code also works.
Test text
Use $1, $2 for numbered groups, $<name> for named groups and $& for the whole match.
Result
Table
How to use this tool
- Type your regular expression, without the surrounding slashes.
- Tick the flags you need, such as global, ignore case or multiline.
- Paste the text to test and read the highlighted matches and the group table.
- Optionally tick replace, enter a replacement and copy the result.
How it works
The tester uses the regular expression engine built into your browser, the same one JavaScript code uses, so a pattern that works here works in your script. Each match is highlighted in the text, and the table lists its position, the full match and every capture group, including named groups written as (?<name>...).
Matching runs in a separate background worker. If a pattern takes too long, usually because nested quantifiers such as (a+)+ make the engine try millions of paths, it is stopped after a second and a half instead of freezing the page.
Good to know
Some quick reminders: \d is a digit, \w a letter, digit or underscore, and \s any space. + means one or more, * zero or more and ? optional. Add ? after a quantifier to make it lazy, so it matches as little as possible. Square brackets list allowed characters, and a caret inside them, as in [^0-9], means "not these".
Other languages have small differences. Python and PCRE support possessive quantifiers and some extra syntax, while JavaScript supports lookbehind only in modern browsers. Test with the same engine your code will use. Because everything runs locally, you can safely test patterns against logs or customer data.
Worked example
After a Diwali stall, a small business owner has a list of leads copied from a notebook app. Before sharing it with a part-time helper, she wants to check a pattern that finds Indian mobile numbers, then mask the last five digits.
Inputs
- Regular expression:
(\+91[ -]?)?([6-9]\d{4})[ -]?(\d{5})\b - Flags: Global and Unicode ticked (the defaults)
- Test text, five lines: "Leads from the Diwali stall:", "Lead 1, +91 98201 45678", "Lead 2, 9819012345", "Office landline 022 2654 1234", "Lead 3 +91-7045123456"
- Also replace matches: ticked, with
$1$2XXXXX
Result
- 3 matches, 3 capture groups, flags
gu - Match 1, position 37–52:
+91 98201 45678, groups "+91 ", "98201", "45678" - Match 2, position 61–71:
9819012345. Group 1 shows "–" because there's no +91 prefix. - Match 3, position 109–123:
+91-7045123456 - Text after replace: "+91 98201XXXXX", "98190XXXXX", "+91-70451XXXXX". The landline is left unchanged, because the pattern needs a 10-digit number starting with 6 to 9.
The pattern only checks that a number looks like a mobile number. It can't tell whether the number is real or still in use.
Names and figures in this example are made up for illustration.
Frequently asked questions
Which regex flavour does this use?
JavaScript (ECMAScript) regular expressions, exactly as your browser runs them.
Why does it only find one match?
Without the global (g) flag a JavaScript regex stops at the first match. Tick Global to find them all.
Why was my pattern stopped?
It took longer than a second and a half, which usually means catastrophic backtracking. Make quantifiers more specific or avoid nesting them.
Can I paste /pattern/gi from my code?
Yes. The slashes are removed. Set the flags with the tick boxes.
Is my text uploaded?
No. Matching happens on your device.