Skip to content
ToolkitHub

Regex Tester

Test regular expressions

Guide

Testing regular expressions safely

By Logappradeep · ServiceNow developer

A regular expression is a compact pattern language for finding text. A few characters can describe an email address, a date, a log line or a URL slug. That power is also what makes regex hard: one misplaced quantifier can match too much, too little, or hang your program. A tester lets you try a pattern against real sample text and see exactly what it matches before you put it in code.

How this tester works

The tool compiles your pattern with the browser's own JavaScript RegExp engine, the same one your front-end and Node.js code use. With the g flag it finds every match in the test text; without it, it reports only the first. For each match you see the matched text and the value of each numbered capture group. Invalid patterns show the engine's error message so you can fix them immediately.

Take the default pattern (\w+)@(\w+\.\w+) against support@toolkithub.in. \w+ matches one or more word characters, @ is literal, and \. is an escaped dot. The full match is the address, group 1 is support and group 2 is toolkithub.in.

The four flags

  • g (global): find all matches instead of stopping at the first.
  • i (ignore case): abc also matches ABC.
  • m (multiline): ^ and $ match at the start and end of each line, not just the whole string.
  • s (dotAll): . also matches newline characters.

Pitfalls developers actually hit

Catastrophic backtracking. Nested quantifiers such as (a+)+$ or (.*,)* can force the engine to try an exponential number of paths when a match fails. Against a string like 30 a characters followed by !, the pattern above can freeze a browser tab or, on a server, become a denial-of-service vector known as ReDoS. Prefer specific character classes like [^,]* over .*, and avoid repeating a group that itself repeats.

Greedy versus lazy. <.+> on <b>hi</b> matches the whole string because + is greedy. Add ? to make it lazy: <.+?> matches each tag separately.

Zero-length matches. Patterns like \b or a* can match an empty string. With the global flag, code that loops over exec() must advance lastIndex manually or it will loop forever; this tester handles that for you.

Flavor differences. JavaScript regex is not identical to PCRE, Python or Java. For example, JavaScript has no possessive quantifiers or atomic groups, and older engines lacked lookbehind. A pattern copied from another language may behave differently here, so test it in the engine you will deploy to.

Everything runs in your browser. Your pattern, flags and sample text are saved in local storage so they are still there next time.

Frequently asked questions

Which regex flavor does this tester use?

It uses JavaScript's built-in RegExp engine, so results match what you get in browsers and Node.js. Other languages such as Python, PHP (PCRE) or Java can differ in syntax and features.

Why does my pattern only return one match?

Without the g flag, JavaScript stops at the first match. Turn on g to find all of them.

What is catastrophic backtracking?

It happens when nested or overlapping quantifiers like (a+)+ make the engine try an exponential number of combinations on a failing input. Rewrite the pattern with more specific character classes to avoid it.

Do I need to escape slashes?

No. Enter only the pattern itself, not the /.../ delimiters, so a forward slash does not need escaping here. In a JavaScript regex literal it would.

Does my test text leave the browser?

No. Matching happens locally, and inputs are stored only in your browser's local storage.