← South Fork Apps

Regex Tester

Pattern & Test String
/ /
Replace with:
Enter a pattern above
Matches
Matches will be highlighted here.
Match Details

No matches yet.

About this tool

Regex Tester

Regex Tester runs a regular expression against your text in real time, highlighting every match and showing the capture groups, so you can build a pattern by watching it work rather than by guessing.

How to use it

  1. Enter your regular expression.
  2. Paste the text to test it against.
  3. Watch matches highlight as you type, and read the capture groups for each match.

Greedy and lazy quantifiers

By default quantifiers are greedy: they match as much as possible and then give characters back only if the rest of the pattern fails. That is why matching an HTML tag with an angle bracket, dot-star, angle bracket swallows everything from the first opening bracket to the last closing one.

Adding a question mark makes a quantifier lazy, so it matches as little as possible. That single character is the fix for the majority of patterns that match far more than intended.

When it helps

  • Building a pattern incrementally with live feedback instead of trial and error in code.
  • Testing a pattern against real sample data before deploying it.
  • Understanding an inherited regex by watching what it actually matches.
  • Extracting fields from log lines or semi-structured text.

Common mistakes

  • Nesting quantifiers, which can cause catastrophic backtracking. A pattern like nested repetition can run for effectively forever on a non-matching input, and this is a real denial-of-service vector.
  • Parsing HTML with regex. HTML is not a regular language and the approach fails on any nontrivial document.
  • Forgetting to anchor a pattern. Without a start and end anchor, a validation regex passes any string that merely contains a match.
Regex Tester interface preview
Screenshot of the live Regex Tester interface.

v1.0