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.
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 $&.
- Enter the patternType the regular expression without surrounding slashes, for example (\d{3})-(\d{4}).
- Set flags and test textAdd flags g, i, m, s, u, y or d and paste the text you want to search.
- 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.
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 toolsEncode or decode URLs and query values with %XX, encodeURI or form rules
Encode special characters as HTML entities or decode entities back to text
Decode a JWT's header and payload, check expiry and verify the signature
Convert YAML to JSON and back, with anchors, merge keys and multiple documents
Beautify messy SQL clause by clause or squeeze it onto a single line
Pretty-print or minify XML and pinpoint errors by line and column