Regex tester / JavaScript regular expression

Test a JavaScript regular expression against sample text in your browser. Shows matches, capture groups, and replace with $1 / $&. Not .NET, Vim, or grep.

How it works
  • . โ€” any character except newline (unless s)
  • \d โ€” digit ยท \w โ€” word character ยท \s โ€” whitespace
  • * zero or more ยท + one or more ยท ? optional ยท {n,m} count
  • (...) capture group ยท [abc] character set ยท | alternation
  • ^ start ยท $ end ยท \b word boundary
  • Replacement uses JavaScript tokens: $1 is group 1, $& is the match, $$ is a literal $.

Enter the pattern only โ€” do not wrap it in /slashes/.

JavaScript tokens such as $1 and $& work here. Leave empty to delete matches.


        
About regex testers

What is a regex tester?

A regex tester runs a regular expression against sample text and shows each match. This page uses the browser JavaScript RegExp API, lists capture groups, and can replace matches.

Enter the pattern without wrapping slashes. Flags are g, i, m, s, and u. This is not .NET, Vim, or grep/PCRE. POSIX classes such as [[:digit:]] are not supported.

Test a regular expression in code

JavaScript
new RegExp("\\w+", "g")
"hello world".match(/\w+/g)
Python
import re
re.findall(r"\w+", "hello world")
re.sub(r"(\w+)", r"[\1]", "hello world")
Flags
g  all matches
i  ignore case
m  ^ $ at line edges
s  . matches newline
u  Unicode

Regex tester FAQ

What is a regex tester?
A regex tester runs a regular expression against sample text and shows each match. This page also lists capture groups and can replace matches using JavaScript $1 and $& tokens.
Which regex flavor does this tester use?
JavaScript. Patterns follow the browser RegExp API, not .NET, Vim, or grep/PCRE. Enter the pattern without wrapping slashes. POSIX classes such as [[:digit:]] are not supported.
How do I replace with capture groups?
Use $1 for group 1 and $& for the whole match. $$ is a literal dollar. Leave the replacement empty to delete matches.
How do I test a regular expression in code?
In JavaScript use new RegExp(pattern, flags) or a /pattern/g literal. In Python use re.findall or re.search. grep -E uses a different flavor.