Utilumo
LightDarkSystem
Guide1 min readUpdated July 1, 2026

How to test a regular expression

Short answer

Paste your pattern and some sample text into a regex tester and watch the matches highlight live. Adjust the pattern until only the intended text matches, then copy it into your code with the right flags.

Why test before you ship

A regex that looks right often matches too much or too little on real input. Testing against representative samples — including edge cases — catches this before it reaches production. For the syntax itself, see regex explained.

Test a pattern

  1. Paste sample textInclude the strings that should match and some that should not.
  2. Enter the patternMatches highlight live as you type, so you see the effect.
  3. Set flagsAdd g for all matches, i for case-insensitive, m for multiline.
  4. Refine and copyTighten the pattern until only the intended text matches.
Try it: Regex TesterTest regex with live match highlighting locally — nothing is uploaded.Open tool
Test the failures tooInclude strings that should NOT match. A pattern that matches your good examples but also matches garbage is worse than no pattern.

Common debugging fixes

  • Escape special characters you mean literally: . ? ( become \. \? \(
  • Use anchors ^ and $ to match the whole string, not just part
  • Prefer lazy quantifiers *? when greedy * grabs too much
  • Remember to add the g flag if you expect multiple matches

References

Questions

What do the g, i, and m flags do?

g finds all matches instead of stopping at the first, i makes matching case-insensitive, and m makes ^ and $ match at line breaks rather than only the string start and end.

Why does my regex match more than expected?

Usually a greedy quantifier like .* is grabbing as much as possible. Make it lazy (.*?) or tighten the character class so it stops where you intend.

Does this send my data anywhere?

No. Utilumo's developer tools parse and transform input inside the browser tab. Nothing is uploaded, stored, or logged.

Keep reading