Developer ToolsA little help for every day

Search by name or task, such as JSON or percentage.

Developer Tools

Regex Tester for JavaScript Regular Expressions

Test a JavaScript regular expression on sample text: matches are highlighted and listed with index and capture groups, and you can preview $1 replacements.

View all tools
ResultUpdates as you type
Matches2
Expression/(\d{3})-(\d{4})/g
Call 555-1234 or 555-9876 today.
#MatchIndexGroups
1555-12345555 | 1234
2555-987617555 | 9876

How to use Regex Tester for JavaScript Regular Expressions

Enter a pattern without slashes, add flags such as g, i or m, and paste your test text. Matches highlight as you type; fill in Replace with to preview a substitution using $1, $2 or $&.

  1. Enter the patternType the regular expression without surrounding slashes, for example (\d{3})-(\d{4}).
  2. Set flags and test textAdd flags g, i, m, s, u, y or d and paste the text you want to search.
  3. Check matches and replaceRead the match count, each match's index and groups, and the replaced text preview.

Example: masking phone numbers with $1

With the default pattern (\d{3})-(\d{4}) and the text Call 555-1234 or 555-9876 today., the tester finds 2 matches at index 5 and 17, with groups 555 and 1234, then 555 and 9876. Enter $1-XXXX in Replace with and the preview reads Call 555-XXXX or 555-XXXX today. $1 refers to the first capture group, $2 to the second and $& to the whole match, and named groups can be referenced by name. Remove the g flag and only the first match is found and replaced.

Flags and JavaScript regex syntax

Patterns run on the browser's JavaScript RegExp engine. g finds every match instead of stopping at the first, i ignores case, m makes ^ and $ match at each line, s lets . match line breaks and u enables full Unicode, including \p{L} property escapes. Lookbehind and named groups work in current browsers. Syntax from other engines may not: possessive quantifiers such as a++ or Python-style named groups written with (?P raise a syntax error. Do not wrap the pattern in slashes, because they are treated as literal characters.

Accuracy and data handling

Validate the result with your project's own tests and runtime rules before using it in production. The calculation runs in your current browser; the tool code does not send the input to a processing API.

Often Used Together

Next step

FAQ

Should I include the slashes around a regex?

No. Type only the pattern, such as \d+, and put flags in the Flags box. Slashes typed into the pattern are matched literally, so /\d+/ finds nothing in ordinary text.

Why is my $1 replacement not working?

$1 only works if the pattern has a capturing group in parentheses. Check the Groups column: if it is empty, put ( ) around the part you want to reuse, or use $& to insert the whole match.

Why do I get a syntax error?

The pattern is not valid JavaScript, often because of an unclosed bracket or parenthesis, a quantifier with nothing before it, or syntax from another regex flavour. The message names the problem.

More Developer Tools

Related tools