Regex Tester

This regex tester checks a regular expression against real text. Every match lights up as you type. The tool lists capture groups with their values. Named groups show by name. A replacement preview shows exactly what a substitution would produce.

Your files never leave this device

Test your pattern Live · JavaScript engine

Write the pattern only, no surrounding slashes.

Flags

0 Matches
Matches highlighted

Use $1, $2 for groups, or $& for the whole match.

How to test a regular expression

  1. Type your pattern without the slashes around it.
  2. Tick the flags you need such as g for all matches.
  3. Paste sample text into the test box.
  4. Check the highlights, the match count and the groups.
  5. Add a replacement to preview a substitution.

What this regex tester gives you

  • Every match highlighted right inside your text.
  • A live match count that exposes greedy or strict patterns.
  • Numbered capture groups for each match.
  • Named groups shown by their names.
  • A replacement preview with $1, $2 and $& support.
  • Clear error messages when a pattern will not compile.

Why a regex tester beats guesswork

Regular expressions are hard to read. They are easy to get slightly wrong. A pattern that looks right may catch one case too many. A pattern that looks strict may miss a rare edge case. Even people who write them daily make these mistakes.

A test against real text removes the guesswork. A greedy pattern shows one huge match instead of several small ones. A strict pattern shows a count of zero. Both problems jump out in a second. In code they stay invisible.

The flags and why g matters most

FlagWhat it does
gFinds every match and not just the first
iIgnores upper and lower case
mLets ^ and $ match at each line
sLets a dot match a new line
uTurns on full Unicode support

A missing g flag is the top reason a regex seems to work only once. The u flag matters for Unicode property escapes. You need it for emoji and other rare characters too.

Greedy versus lazy

This is the most common regex mistake. Quantifiers like * and + are greedy. They grab as much as they can. They give back only what they must.

Apply <.+> to <a>text</b> and see what happens. It matches the whole string and not just the first tag. The .+ part swallowed everything. The final > still found a match at the end.

Add a question mark to make the quantifier lazy. <.+?> stops at the first >. The highlights on this page show the difference at once. That is why testing catches the bug and reading rarely does.

Capture groups and replacements

Parentheses capture text. The tool numbers each group from one. The order follows the opening brackets. This tester lists every group for every match. It marks optional groups that did not take part.

Named groups look like (?<year>\d{4}). The tool shows them by name. That reads far better than counting brackets in a long pattern.

The replacement box previews a substitution. Use $1 and $2 for numbered groups. Use $& for the whole match. Use $<name> for a named group. You see the result before you touch real data.

This tool uses the JavaScript engine

Regex syntax differs between languages more than people expect. Lookbehind needs a recent browser. Some other engines lack it. Possessive quantifiers and atomic groups exist in PCRE but not here. Named group syntax also varies. Test in your target language before you ship.

Common regex tester problems

My pattern shows an error

A bracket may lack its partner. A special character may need a backslash. Read the error and check that spot.

The match count is zero

Check the case of your text. Try the i flag. Check for extra spaces in the pattern.

Handy patterns to start with

GoalPattern
Digits only^\d+$
Simple email check^[^@\s]+@[^@\s]+\.[^@\s]+$
Four digit year\b(19|20)\d{2}\b
Extra spaces {2,}

Treat these as starting points. Paste your own sample text and adjust each pattern until the highlights look right. Real data always holds a surprise or two. A quick test finds it before your users do.

Tips for writing better patterns

  • Start small and add one piece at a time.
  • Test with text that should fail as well as text that should pass.
  • Use named groups in long patterns.
  • Anchor with ^ and $ when you check a whole value.

Who uses a regex tester?

Developers validate emails and phone numbers. Data analysts pull values from logs. SEO teams write redirect rules. Writers find and replace patterns across long drafts.

Your test text stays private

Your browser runs every match. Log extracts and customer data never leave your device. Need to clean up the text first? Use the text cleaner. Want to check JSON syntax instead? Try the JSON validator. Want to split a link into parts? The URL parser helps.

Frequently asked questions

Why does my pattern match only once?

The g flag is off. Without it the engine returns only the first match. Tick g to find them all.

Why does my pattern match far too much?

Quantifiers are greedy by default. Add a question mark after them to make them lazy.

Do I type the slashes around the pattern?

No. Type the pattern only. Set flags with the checkboxes.

Will a pattern from this regex tester work in Python or PHP?

Not always. This tool uses the JavaScript engine. Lookbehind and named groups differ in other languages.

How do I use a group in a replacement?

Type $1 for the first group and $2 for the second. Type $& for the whole match.

Does the tool upload my test text?

No. Your browser does the matching. Your text stays on your device.