Test a regular expression

Enter a pattern and flags, paste your text, and every match is listed with its index, line number and capture groups, then highlighted in the text below. An optional replacement field shows what a find-and-replace would produce. Uses the JavaScript regular expression engine, the same one your browser and Node.js run.

✓ Runs in your browser — nothing uploaded Free, no sign-upNo watermark

g global, i ignore case, m multiline ^$, s dot matches newline, u unicode.

How to use the Regex Tester

  1. Type the pattern in the options box, without the surrounding slashes.
  2. Set the flags — g is added automatically so every match is found.
  3. Paste the text to search; matches highlight as you type.
  4. Optionally add a replacement string using $1, $2 or $<name> to reuse capture groups.

Flags

FlagEffect
gFind every match rather than stopping at the first (added automatically here)
iCase-insensitive
m^ and $ match at each line break, not only at the ends of the text
s. also matches a newline
uUnicode mode — required for \p{L} and for astral characters such as emoji
ySticky: matches only at the current position

Groups

Parentheses capture: (\d{4})-(\d{2}) gives group 1 and group 2, listed under each match. Name them for readability with (?<year>\d{4}) and refer to them as $<year> in a replacement. Use a non-capturing group (?:…) when you only need to group for alternation or repetition — it keeps the numbering clean and is slightly faster. Lookahead (?=…), negative lookahead (?!…) and both lookbehind forms are supported by every current browser.

Replacement syntax

In the replacement field, $1 inserts the first capture group, $& the whole match, $<name> a named group, and $$ a literal dollar sign. Swapping a date around is one line: pattern (\d{4})-(\d{2})-(\d{2}), replacement $3/$2/$1.

Catastrophic backtracking

The JavaScript engine backtracks, and some patterns make it explore an exponential number of paths. Nested quantifiers are the classic trigger: (a+)+b against a long run of a's can hang a tab for minutes, and the same shape hidden inside (\s*\w+)*$ has caused real production outages. This tester stops after four seconds and tells you what happened. The fixes are to avoid nesting quantifiers, to make inner parts possessive-by-construction using atomic alternatives, and to anchor the pattern so it fails early.

Portability

Regular expression dialects differ. JavaScript has no \A, \z or inline modifiers such as (?i), its lookbehind was only widely available from 2018, and POSIX classes like [:alpha:] are not supported — use \p{L} with the u flag instead. A pattern that works here will usually work in Node.js unchanged, but check before moving it to PCRE, Python, Go or a database engine.

A note on what regex is bad at

Nested structures — HTML, JSON, source code — are not regular languages, so no pattern can parse them reliably. Use a parser for those. Regular expressions are the right tool for tokenising flat text: log lines, CSV cells, identifiers, dates, and find-and-replace across a file.

Frequently asked questions

Do I include the slashes around the pattern?

No. Type only the pattern itself and put the flags in the separate flags box.

Which regex dialect is used?

JavaScript, the ECMAScript engine built into your browser — the same behaviour you get in Node.js. PCRE, Python and Go differ in places.

Why did it stop and warn about backtracking?

The pattern took more than four seconds, which almost always means nested quantifiers such as (a+)+ exploring exponentially many paths. Rewrite it or test on a shorter sample.

Can I test a replacement?

Yes. Fill in the replacement field and the result appears below the match list. Use $1, $& and $<name> to reuse captures.

Privacy

This tool runs entirely inside your browser using WebAssembly and the Canvas/File APIs. Your files are never uploaded to ToolFlint or any third party; you can verify this in your browser's network tab or by switching to airplane mode after the page loads. Read how we process files.

Last updated 2026-09-23.