How to test a regular expression
- Type your pattern without the slashes around it.
- Tick the flags you need such as g for all matches.
- Paste sample text into the test box.
- Check the highlights, the match count and the groups.
- 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
| Flag | What it does |
|---|---|
| g | Finds every match and not just the first |
| i | Ignores upper and lower case |
| m | Lets ^ and $ match at each line |
| s | Lets a dot match a new line |
| u | Turns 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
| Goal | Pattern |
|---|---|
| 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.