Skip to content
Technology·1 min read·

Regex tester

Test a JavaScript regular expression against pasted text and list the first matches with their positions.

The answer

The pattern is compiled as a JavaScript regular expression. Flags may be g, i, m, s, u, or y. The result lists up to 30 matches and the index where each one starts.

Optional: g, i, m, s, u, or y.

Result

Matches shown

2

Matches

0: aa
5: a

What do you want to do next?

How this works

The page uses the JavaScript regular-expression language. A pattern that does not compile is rejected with that fact, not with a guessed correction.

Patterns that nest open-ended quantifiers, or that are longer than 80 characters, are refused. A match that runs too long is stopped. This is a tester for ordinary patterns, not a place to explore catastrophic backtracking.

Practical steps

  1. 1

    Enter the pattern without surrounding slashes.

  2. 2

    Add flags only if you need them. Leave the box empty for a global search.

  3. 3

    Paste the text and read the index in front of each match.

Examples

  • Pattern “a+” against “aardvark”

    The first match is the two a’s at the start, and a later single a matches too.

Common mistakes

  • ×

    Wrapping the pattern in /slashes/ and then wondering why the slashes are matched literally.

Frequently asked questions

Do I include the slashes?

No. Type the pattern only. Put flags in the flags box.

Why was a pattern rejected as too open-ended?

Nested quantifiers such as (a+)+ can stall a matcher. Rewrite the pattern so the repetition is not nested that way.

Continue reading