Regex Lab

Test JavaScript regular expressions with live matches and groups. Free online regex tester for developers.

Tool input stays in your browser. The site may use cookies for ads.
//gm
Quick Patterns:
0 matches
Hello, my email is john.doe@example.com You can also reach me at jane@company.org Visit our website at https://www.example.com Call us at (123) 456-7890 or 123-456-7890 Our API is at http://api.example.com/v1 Date: 2024-01-27, Color: #FF5733

JavaScript RegExp flags

  • g — global; find all matches; mutates lastIndex
  • i — ignore case
  • m — ^/$ match line starts/ends
  • s — dotAll; . matches newlines
  • u — Unicode; proper code-point escapes
  • y — sticky; match only at lastIndex
  • d — indices; expose match start/end offsets

Worked example

const re = /\b(\w+)@(\w+)\.(\w+)\b/g;
const s = "a@x.com b@y.org";
[...s.matchAll(re)].map(m => m[0]);
// → ["a@x.com", "b@y.org"]

// Catastrophic-style pattern (do not run on huge input):
// /^(a+)+$/ against "aaaaaaaaaaaaaaaaaaaaX"

Lookbehind and ReDoS

Variable-length lookbehind is supported in modern V8/SpiderMonkey but remains a portability footgun. For user-controlled patterns or inputs, length-limit the string and avoid nested +/* on the same character class.

Frequently Asked Questions

Why does my pattern match once without the g flag but “stall” in a loop?

With g, lastIndex advances on the RegExp object. Reusing the same /pat/g instance across exec calls is stateful. Create a fresh RegExp or reset lastIndex when looping.

Does JavaScript support lookbehind?

Yes in modern engines: (?<=...) and (?<!...). Older browsers may throw. Prefer feature detection or transpile carefully for legacy targets.

What is catastrophic backtracking?

Nested quantifiers like (a+)+$ on long non-matching strings can explore an exponential number of paths and freeze the tab. Prefer possessive-style thinking, atomic groups where available, or simpler parsers for untrusted input.

Related Tools