Regex Tester
Type a JavaScript regular expression and some sample text to see every match, its capture groups and a replace preview as you type.
| # | Match | Index | Groups |
|---|
How to test a regular expression
- Type your pattern into the Regular expression box without the surrounding slashes. For example, type
\d+, not/\d+/. - Tick the flags you need: g to find every match, i to ignore capital letters, m so
^and$work on each line, s so a dot also matches line breaks, and u for full Unicode support. - Paste the text you want to search into Test text. Matches are highlighted as you type.
- Read the table underneath. It shows each match, where it starts and what every capture group contains.
- Optionally, type a replacement using
$1,$2and so on, to preview the text after a find-and-replace.
If the pattern contains a mistake, such as an unclosed bracket, the error message from the browser is shown instead of results.
Worked example
The page opens with a pattern for UK-style dates, \b(\d{1,2})/(\d{1,2})/(\d{4})\b, and the sentence "Invoices dated 3/11/2026 and 14/11/2026 are due. The note 2026/11/20 is a different format." The result reads 2 matches. The first, 3/11/2026, starts at position 15, with group 1 as "3", group 2 as "11" and group 3 as "2026". The second, 14/11/2026, starts at position 29. The date written as 2026/11/20 is correctly ignored, because the year comes first.
Type $3-$2-$1 in the replace box and the preview becomes "Invoices dated 2026-11-3 and 2026-11-14 are due." The groups have been swapped round to put the year first. A real conversion would also pad single digits with a leading zero, which is a good reminder that previews help you spot details before changing real data.
How it works
The page builds a JavaScript RegExp from your pattern and flags, then runs it over the text in your browser. Without the g flag, only the first match is reported, exactly as in code. Positions are counted from zero, the same way JavaScript counts characters. Because everything runs locally, you can safely test patterns against log files or customer data.
Common building blocks
A handful of pieces cover most everyday patterns. \d matches a digit, \w matches a letter, digit or underscore, and \s matches a space, tab or line break. Square brackets list allowed characters, so [A-Z] means any capital letter. Curly brackets set how many times something repeats: \d{4} is exactly four digits and \d{1,2} is one or two. Round brackets create a capture group that you can reuse in a replacement, and a vertical bar means "or", as in colou?r|shade. Put ?: just inside a bracket, as in (?:Mr|Mrs), when you need grouping without capturing.
Tips
- Start simple and add detail gradually. A short pattern that works is easier to extend than a long one that does not.
- Use
\bword boundaries to stop a pattern matching inside a longer number or word. - Escape dots in web addresses and file names:
\.matches a full stop, but a plain dot matches any character. - Prefer lazy quantifiers, such as
.*?, when you want the shortest possible match between two markers.
Frequently asked questions
Which regex flavour does this use?
JavaScript's. Most everyday syntax is shared with PHP, Python and others, but some advanced features differ, so retest in your own language for complex patterns.
Why does my pattern find only one match?
The g flag is probably off. Without it, a regular expression stops after the first match.
Can a pattern freeze the page?
Badly nested repeats, such as (a+)+, can take a very long time on certain text. If the page slows down, simplify the pattern.
Is my text uploaded?
No. Matching happens entirely in your browser, so you can safely paste log files, exported spreadsheets or customer records to test a pattern before running it on live data.