A regular expression usually fails quietly. The pattern looks right, the code runs, and then a log line in an unexpected format slips through, or a valid address gets rejected. Testing the pattern on its own, against text you control, is how you catch that before it ships.

This guide shows how to test a regular expression with the free Regex Tester on Ovatly. It covers building a pattern in small steps, reading the match list the tester returns, choosing flags deliberately, and using the tester's plain-language errors to debug. The tester runs a JavaScript regular expression against your text live and lists every match with its position and capture groups.

Contents

  • Quick answer
  • What the match list actually tells you
  • Flags are part of the pattern
  • How to test a regular expression, step by step
  • Worked example: finding numbers, then splitting an email address
  • Limitations and alternatives
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Open the Regex Tester, type your pattern in the Pattern field without slashes, add any flags you need, such as g, in the Flags field, and paste or type your test text. The tester lists every match with its text, its index in the string and any capture groups. Build the pattern one piece at a time and check the match list after each change, instead of writing the whole pattern at once and hoping. Without the g flag only the first match is reported, and results stop at 500 matches. If the pattern is invalid, the tester shows a plain-language error rather than a stack trace.

What the match list actually tells you

Each match in the list shows three things. The matched text is the exact substring the pattern accepted. The index is where that substring starts in your test text, counted in characters from the beginning. The groups show what each pair of parentheses captured inside the match.

The index is the detail people skip, and it is the one that catches anchoring mistakes. If you expected a match to start at index 0 and it starts at index 6, the pattern matched later in the string than you intended, which usually means it needs an anchor or a tighter opening. Groups matter because most real patterns are not just checking a string, they are pulling pieces out of it, and the group list shows exactly which piece landed where. Named groups written as (?<name>...) are supported, and their values appear in each match's details next to the numbered groups.

One safety behaviour is worth knowing: a pattern that can match the empty string is advanced safely so the tester never loops forever, and results stop at 500 matches. A list that stops at exactly 500 is a sign your pattern is matching far more than you meant it to.

Flags are part of the pattern

Flags change what the same pattern does, so set them on purpose rather than by habit. They go in the Flags field, separate from the pattern: g for global, i for case-insensitive, m for multiline, s so the dot matches line breaks too, u for Unicode mode and y for sticky matching.

The flag that surprises people is g. Without it, only the first match is reported, which matches how most code uses a pattern. That is fine when you only care whether a string passes, and misleading when you are counting matches or extracting all of them. Add g when you want the full list. The m flag matters when your test text has several lines and you use ^ and $: with m, those anchors work at line boundaries instead of only at the ends of the whole text.

How to test a regular expression, step by step

  1. Open the Regex Tester.
  2. Start with the smallest piece of the pattern that should match something, for example \d+ for a run of digits, and type it in the Pattern field without slashes.
  3. Add the flags you need in the Flags field, starting with g if you want every match.
  4. Paste or type test text that includes cases that should match and cases that should not.
  5. Read the match list: check each match's text, its index and its groups against what you expected.
  6. Add one piece to the pattern at a time, a character class, a quantifier, an anchor, a group, and re-read the match list after each change. When the list changes in a way you did not expect, the last piece you added is the suspect.

Worked example: finding numbers, then splitting an email address

Take the pattern \d+ with flag g, against the text Order 123 ships in 45 days. The tester reports two matches: 123 at index 6 and 45 further along. That confirms the pattern finds digit runs and nothing else in this text, and the index of the first match tells you it begins right after Order , exactly where you would expect.

Now a pattern with groups: (\w+)@(\w+)\.com against [email protected]. The match shows group 1 as ada and group 2 as example. If you were parsing addresses, those groups are the pieces your code would receive, so seeing them listed separately is the real test result. Try the same pattern without the g flag and you get the same first match only; try it against [email protected] and you get no match at all, because the pattern insists on .com. Both outcomes are useful information, and both are cheaper to learn here than in production code.

Limitations and alternatives

The tester uses JavaScript's RegExp engine, so syntax follows JavaScript rules, which differ slightly from PCRE, Python or grep flavours. A pattern that passes here may need small changes in another language, and a pattern copied from a Python or PCRE source may behave differently here. Test in the flavour you will ship, or at least re-test after porting.

Pathological patterns can still bite: nested quantifiers on long text can cause catastrophic backtracking and make your browser tab busy. If the tab hangs, simplify the pattern, usually by making an inner quantifier more specific. The tester also caps results at 500 matches, so it is a tool for checking behaviour on samples, not for processing a whole file. For bulk work, take the pattern you have proven here into your editor or your code, where find-and-replace and scripting tools can apply it at scale.

Common mistakes

  • Writing the pattern with slashes. The Pattern field takes the pattern body only; slashes and trailing flags typed into it become literal characters that never match.
  • Forgetting the g flag. You see one match, assume the pattern is broken or finished, and miss the other matches entirely.
  • Writing the whole pattern at once. A long pattern that fails gives you no clue which part failed. Build it in pieces and check the match list as you go.
  • Testing only strings that should pass. A pattern that matches everything also matches your good examples. Always include near misses that should fail.
  • Ignoring the index. The match text can look right while the match starts in the wrong place. The index is how you notice.

FAQs

Do I write the pattern with slashes? No. Type just the pattern body, like \d{3}-\d{4}, and put the flags in their own field. The slashes you see in code are the language's literal syntax, not part of the pattern itself.

Why does the tester say invalid pattern? Common causes are an unclosed bracket or parenthesis, a trailing backslash, or a quantifier with nothing to repeat. The tester shows a plain-language error instead of a stack trace, so read it and check the pattern at the spot it points to.

Can I test named groups? Yes. Use (?<name>...) in the pattern and the named values appear in each match's details, alongside the numbered groups.

Why is only the first match shown? Because the g flag is missing. Without g, only the first match is reported, matching how most code uses a pattern. Add g in the Flags field to list every match, up to the tester's limit of 500.

Is my test text uploaded anywhere? No. The Regex Tester runs in your browser on your device, so the patterns and text you test with stay local.

Conclusion

Testing a regex is a loop, not a single check: small pattern, honest test text, read the match list closely, then extend. The Regex Tester keeps that loop fast and private, since it runs in your browser. Once your pattern behaves, put it to work on real validation jobs with the worked patterns in Regex Patterns for Email, URL and Phone Number Validation, and browse the rest of the Developer Tools guides for more tools in this category.