Regular Expression Tester With Match Highlighting
Test regular expressions against sample text with live match highlighting.
About Regex Tester
Regex Tester lets you try a regular expression against your own sample text and see the outcome instantly. Type the pattern in the Pattern box without surrounding slashes, choose flags with the Global, Ignore case, Multiline and Dot-all checkboxes, and paste text underneath. Matches are highlighted in the text, and a list below gives each match's position, its text and any capture group values.
People use it to work out a pattern before putting it into code, to check a validation rule for a form, or to pull fragments out of messy text such as exported logs. In Pakistan common test cases include a mobile number like 0300-1234567 or a CNIC written as 12345-1234567-1, where a small mistake in the pattern quietly rejects valid input.
The tool runs JavaScript's built-in RegExp engine, so syntax that works here also works in browsers and Node.js, though not always in Python, PHP or .NET. Only the g, i, m and s flags are offered. There is no replace feature, no Unicode (u) flag and no time limit, so a badly written pattern can freeze the tab.
How to use Regex Tester
- Type your pattern into the Pattern box, for example \d{5}-\d{7}-\d, without any / characters at the start or end.
- Tick the flags you need. Global (g) is on at the start; Ignore case (i), Multiline (m) and Dot-all (s) are off.
- Paste or type your sample text into the large box. Everything refreshes on each keystroke.
- Read the status line: it reports how many matches were found, or shows "Invalid regex:" with the reason if the pattern cannot be compiled.
- Look at the highlighted copy of your text to see where matches fall, then scroll the list underneath for each match's index and group values.
Tips for best results
- With Global (g) unticked only the first match is reported. That is handy for a yes-or-no check, but misleading when you expect every occurrence.
- \w, \b and \d understand only ASCII letters and digits here, so \w+ skips Urdu or Arabic words. Use a range such as [\u0600-\u06FF] for Arabic-script letters; \p{L} will not work because the u flag is not available.
- Group values are listed in order, without numbers or names, and groups that did not take part are left out. Count the parentheses in your pattern to match values to groups.
- The index after "at index" starts at 0 and counts UTF-16 units, so an emoji counts as two. Empty matches, from patterns like \d*, are listed but have nothing to highlight.
- Avoid nested repeats such as (a+)+ on long text. The pattern re-runs on every keystroke with no timeout, and catastrophic backtracking can leave the page unresponsive until it finishes.
Frequently asked questions
Which regex flavor does this use?
JavaScript's native RegExp engine, the same one used in browsers and Node.js.
Can I see capture groups from each match?
Yes, every match lists its full text along with the values of its capture groups. Groups that did not take part in a match are left out.
Do I need to put slashes around the pattern?
No. Type just the pattern, such as \d+, and set flags with the checkboxes. If you paste /\d+/g, the slashes are treated as characters that must appear in the text.
Why does my pattern show only one match?
Check that Global (g) is ticked. Without it the tester stops after the first match, exactly like a JavaScript regex that lacks the g flag.
How can I test a Pakistani mobile number or CNIC?
Try \b\d{5}-\d{7}-\d\b for a CNIC with dashes and 03\d{2}-?\d{7} for a local mobile number such as 0300-1234567. These check the shape only, not whether a number or CNIC actually exists.
Can I replace text with this tool?
No. It finds and highlights matches but has no replacement field. Build and test the pattern here, then apply it in your editor or code.