Skip to content

RegExp in this browser, with indexes

Test a JavaScript regular expression

Regular expressions in JavaScript are not the same as PCRE or .NET. This page uses the RegExp your browser already ships, so a match here is a match in frontend code.

Type the pattern without slashes. Flags are checkboxes: g, i, m, s, u, and v when the browser allows v. The search always lists non-overlapping matches, up to 50. An empty pattern is refused, because it would match at every position. Text longer than 8,000 characters, or a pattern longer than 200, is refused so a nested quantifier cannot stall the tab as easily. Groups are the captures after the full match. Named groups are not listed separately.

The pattern and the sample stay in this tab. They are not sent to a regex service.

This tool runs in your browser. Turn on JavaScript to use it.

A whole word, not a prefix

\\b is a word boundary in a JavaScript string you would write in code. In this box you type \b, because the box is the pattern itself, not a string literal.

Pattern
\bcat\b
Text
the cat catalogs a category
Match
cat at index 4

How to use it

  1. 1Enter the pattern and tick the flags you would pass to new RegExp.
  2. 2Paste a short sample. The page lists each match and its index.
  3. 3Adjust the pattern. An invalid pattern shows the syntax error instead of a match list.

Good to know

  • Lookbehind and the v flag depend on the browser. A syntax error means this browser rejected it.
  • The global flag is applied for the list even if you leave it off, so you can see every match. It does not change the pattern text.
  • Catastrophic cases are limited by length, not by a separate timeout.

Questions

Why did a pattern from another language fail?

PHP, Python, and PCRE accept constructs JavaScript does not. This page will not translate them.

Does it replace the text?

No. It only reports matches. Rewriting the string is left to your editor.

What is index 0?

The first character of the sample. The count is in UTF-16 code units, which is how JavaScript measures strings.

Related tools

  • Sort, trim, and count lines

    Lists in a text box are awkward to clean by hand. This page trims, filters, sorts, or reverses the lines, and always shows the counts.

  • Convert identifier case

    Code style is mostly about where the word breaks sit. This page finds those breaks and prints the same words in the forms languages usually want.

  • Compare two texts by line

    Two copies of a list or a config rarely differ in every line. This page marks lines that only the first text has and lines that only the second text has.