Skip to contentSkip to the inputSkip to the result

Regex tester

See where a regular expression matches

Loading tool

Instructions

Regex tester

How to use

  1. Enter a pattern and flags, then the text to test.
  2. In the replacement, $1 or $<name> stands for a group.

Supported input

  • JavaScript regular expressions.
  • Text up to 200,000 characters and patterns up to 500.
  • Up to 2,000 matches are listed, named groups by name.
  • The pattern, flags and replacement go into the address so a link carries them; the test text does not.

Input example

\d{3}-\d{4} · call 010-1234-5678

Result example

1. "010-1234" @3

Troubleshooting

  • Nothing is produced for empty input.
  • Split very long text into parts.

Limitations

  • Syntax can differ from other engines such as PCRE or Python.
  • A pattern that runs for more than 2 seconds is stopped with a message.

How it works

  • Runs a regular expression on text, highlights each match and lists its groups, and previews a replacement.

Seeing exactly where a regular expression matches, and why

What people test here

  • A validation pattern, checked against a pasted list of values that should pass and values that should not, before it goes into code
  • An expression for pulling order numbers or error codes out of a long log
  • A rearranging replacement with $1 and $2, previewed before you press Replace All in an editor
  • A pattern copied from Python or PCRE documentation, to see whether it means the same thing in JavaScript

How the matching runs

The tool uses your browser’s own JavaScript regex engine and walks through the text match by match. The number after @ is where the match starts, counted from 0 in UTF-16 code units, so after an emoji, which takes two units, it no longer agrees with the characters you would count by eye.

Empty matches count. Run x* over "abc" and you get four empty matches, at 0, 1, 2 and 3; after each one the search moves on a unit so it cannot loop on the same spot. The work happens in a Web Worker, off the page, which is why a runaway pattern cannot freeze the tab.

Worked example: swapping surname and given name

  1. 1Put "Kim, Minji" and "Lee, Jun" on two lines and use ^(\w+), (\w+)$. With no flags, ^ and $ mean the start and end of the whole text, so there are 0 matches.
  2. 2Add m to the flags. Now ^ and $ apply to each line and there are 2 matches.
  3. 3Type $2 $1 into Replace with. The result is "Minji Kim" and "Jun Lee".
  4. 4Replacements understand a few more tokens. On 2026-10-24, (\d+)-(\d+)-(\d+) with "$3.$2.$1 ($&) $$ $4" gives "24.10.2026 (2026-10-24) $ $4": $& is the whole match, $$ a literal dollar sign, and $4, a group that does not exist, stays as typed.

Non-English text and the u flag

  • \w means ASCII letters, digits and underscore only. Over "김민지, 이준" and "Café", \w+ finds a single match: "Caf".
  • For Korean, [가-힣]+ finds complete syllables (김민지, 이준) but misses consonant-only text such as ㅋㅋ, which sits outside that range.
  • With the u flag, \p{L}+ finds 김민지, 이준 and Café alike. It is the script-neutral way to say "letters".
  • A single dot over "😀 ok" gives 5 matches without u, because the emoji splits into two halves, and 4 with it.
  • \d is 0–9 even with u, so it skips the Arabic-Indic ٣ and the full-width 3.

When a pattern suddenly takes seconds

Nested repetition makes a failing match try twice as many paths for every extra character. Timed on Node.js 23, which runs the same V8 engine as Chrome, ^(a+)+$ against a run of a’s followed by ! took 7 ms with 20 a’s, 108 ms with 24, 436 ms with 26, 1.7 s with 28 and 7.0 s with 30. The tool stops anything that runs past 2 seconds, so it would cut in between 28 and 30.

The equivalent ^a+$ took 0.1 ms on 26 a’s. On a server, one line of user input can pin a CPU with a pattern like the first, which OWASP files as a denial-of-service attack called ReDoS. Collapse the nested repeat into one, and cap the input length if you cannot.

Moving a pattern between languages

  • Python’s named groups, (?P<name>…), fail in JavaScript with "Invalid group"; write (?<name>…). Python’s replacement syntax \1 and \g<name> becomes $1 and $<name>.
  • Possessive quantifiers such as a++ and atomic groups exist in PCRE and in Python 3.11 and later, but not in JavaScript, which reports "Nothing to repeat".
  • Python’s \d matches digits from other scripts by default, so the same pattern can match more there than here.
  • Lookbehind does work in JavaScript: (?<=\$)\d+ over "price: $10, $250" finds just 10 and 250.
  • JavaScript’s d and v flags are not used by the tool; type them and the result lists them under Ignored flags.

Checked

Frequently asked questions

How do I write a pattern for phone numbers?

\d{2,3}-\d{3,4}-\d{4} means 2–3 digits, a hyphen, 3–4 digits, a hyphen and 4 digits, so it finds both 010-1234-5678 and 02-345-6789. Add \b at both ends so it does not match part of a longer number.

I pasted '\\d' from my code and nothing matches.

This box takes the pattern itself, so use a single backslash. The \\d you write inside a JavaScript or Java string means a literal backslash followed by d here; enter \d instead.

Do I need to add the g flag?

No. g is always on so every match is found. Use the flags box for i (ignore case), m (^ and $ per line), s (dot matches line breaks) u (Unicode) and y (sticky). Any other letter is not used, and the result says it was ignored.

Can I preview replacing the matches?

Type into Replace with and the result shows the text with every match replaced. $1 is the first group, $<year> a group named with (?<year>…), and $& the whole match. With (?<y>\d{4})-(\d{2}) and $2/$<y>, 2026-10 becomes 10/2026.