Regex tester

Try a JavaScript regular expression against sample text and inspect each match.

Runs locally in your browser. Nothing is uploaded.

JavaScript syntax, without slash delimiters.

Flags

Used by the Replace button. An empty replacement deletes each match.

How to test a pattern

Enter a JavaScript regular expression without the surrounding slashes, choose flags, and paste the text to search. Find matches lists every match, the index where it starts, and the capture groups. Numbered groups are 1, 2, 3, and named groups use the name you wrote in the pattern. Replace applies the replacement string with the flags you selected. Include g when you want every match replaced. Without g, JavaScript replaces the first match only, and this page does the same.

The engine is the one in your browser, which is the same family you get from new RegExp in application code. A pattern that works in Python, PCRE, or a Java Matcher can still fail here, or succeed with a different group. Lookahead and lookbehind are available in current browsers. Possessive quantifiers and some Unicode property escapes differ. When you are debugging a production service, match the language of that service. Use this page for JavaScript, including the scripts and the JSON you clean up before the JSON formatter.

Flags, empty matches, and runaway patterns

i ignores case. m makes ^ and $ match around line breaks. s lets a dot match a newline. u turns on Unicode mode, which you want when the pattern uses the u flag’s stricter escapes. The sticky flag y is refused, because a tester that moves lastIndex by hand is easier to misread than it is to learn. An empty match, such as a* against an empty spot, advances one character so the search cannot spin in place.

Some patterns take exponential time. A classic is a pile of nested quantifiers against a long string that almost matches. The search runs in a worker and is stopped after about a second. You get an error instead of a frozen tab. That limit is a safety rail, not a proof that the pattern is fast enough for a hot loop. Shorten the sample and simplify the pattern. The word counter is the simpler tool when you only needed a length.

Common questions

Why did the slash in my pattern break?

Do not include the / delimiters. If the pattern itself contains a slash, write it as a normal character. There is no need to escape it for this box, because the box is not a slash-delimited literal.

Where are the global indexes?

Each row shows the start index in the text. The match value is the full match, group 0. Groups that did not participate are omitted rather than shown as empty, so you can see which alternative actually fired.

Can I test a pattern against a whole file?

Keep the sample under 20,000 characters. A tester that accepts a multi-megabyte log on the main thread is how pages lock up. Cut the sample down to the lines that matter.

Is the pattern sent to a regex service?

No. The worker is a local script. The pattern and the text are posted to that worker in the same browser, not to a network endpoint.