Online Regex Tester
Test regular expressions as you type: highlighted matches, captured and named groups, replacement with $1. Ten common examples load in one click and a cheat sheet sums up character classes, quantifiers, anchors, groups and flags. Everything runs in your browser.
Regular expression tester
Common examples:
Results
Highlighted text
Text after replacement
Syntax cheat sheet
JavaScript regular expression syntax, as used by this tester.
Characters
. | any character except a line break (any with s) |
\d \D | a digit 0-9 / anything but a digit |
\w \W | unaccented letter, digit or _ / the opposite |
\s \S | space, tab, line break / the opposite |
[abc] | one of a, b or c |
[^abc] | any character except a, b and c |
[a-z0-9] | a range of characters |
\p{L} | a letter in any language, accents included (u flag) |
\. \* \( \\ | special character taken literally |
Quantifiers
* | 0 or more times |
+ | 1 or more times |
? | 0 or 1 time (optional) |
{3} | exactly 3 times |
{2,} | 2 or more times |
{2,5} | 2 to 5 times |
*? +? | “lazy” version: as few as possible |
Anchors
^ | start of text (of each line with m) |
$ | end of text (of each line with m) |
\b | word boundary |
\B | not a word boundary |
Groups and alternation
(abc) | capturing group, reusable as $1 |
(?:abc) | non-capturing group |
(?<name>abc) | named group, reusable as $<name> |
\1 | repeats the text captured by group 1 |
a|b | a or b |
Lookarounds
x(?=y) | x followed by y |
x(?!y) | x not followed by y |
(?<=y)x | x preceded by y |
(?<!y)x | x not preceded by y |
Replacement
$1 $2 | text of group 1, 2… |
$<name> | text of the named group |
$& | the whole match |
$$ | a literal $ sign |
Flags
g | all matches |
i | ignore case |
m | ^ and $ apply to each line |
s | dot matches line breaks |
u | Unicode mode (\p{…}, emoji) |
y | “sticky” search from lastIndex |
Tools in the same category
List of tools similar to Regex Tester
Popular tools
List of popular tools related to Regex Tester
Related articles
Articles related to the tool Regex Tester
Test a regular expression: how to use it
The tester uses JavaScript’s regular expression engine (RegExp), the same as in browsers and Node.js. Matches are highlighted in the text and listed with their groups.
How to use it
- Enter the pattern without the slashes, or load a common example.
- Add the flags you need, for example
gfor every match andito ignore case. - Paste the text: the result updates as you type.
- To transform the text, enable replacement and use
$1or$<name>to reuse groups.
Regex and form validation
A regex checks the format of a value, not whether it is real: it accepts an email address that does not exist, an unassigned postcode or 31 February. For a form, combine it with a suitable HTML field (type="email", pattern) and server-side checks. Also avoid patterns so strict that they reject valid data, such as addresses containing + or hyphenated names.
Slow regexes
Some patterns with nested quantifiers, such as (a+)+$, can take exponential time to fail on long text (“catastrophic backtracking”). If the tester seems frozen, simplify the pattern: prefer precise classes ([^,]*) to .* and avoid repeating groups that are themselves repeated.
Frequently asked questions
Why do I only get one match?
Without the g flag, JavaScript stops at the first match, and replacement only applies to it. Add g to get them all.
Why does \w not match accented letters?
In JavaScript, \w only matches [A-Za-z0-9_]. To include é, ç or ü, use \p{L} with the u flag, for example [\p{L}\d_]+.
Do expressions written for PHP or Python work?
The basic syntax is shared, but some features differ between languages (inline modifiers, atomic groups, named group syntax). The result shown reflects JavaScript’s behaviour.
How do I search for a dot or a parenthesis?
Put a backslash in front: \., \(. The characters to escape are . * + ? ^ $ { } ( ) | [ ] \ /.