Skip to main content
ToolSmartly

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:

/ /
Flags: g (all), i (ignore case), m (multiline), s (dot matches all), u (Unicode)

Results

0 match(es) found

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 \Da digit 0-9 / anything but a digit
\w \Wunaccented letter, digit or _ / the opposite
\s \Sspace, 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)
\bword boundary
\Bnot a word boundary

Groups and alternation

(abc)capturing group, reusable as $1
(?:abc)non-capturing group
(?<name>abc)named group, reusable as $<name>
\1repeats the text captured by group 1
a|ba or b

Lookarounds

x(?=y)x followed by y
x(?!y)x not followed by y
(?<=y)xx preceded by y
(?<!y)xx not preceded by y

Replacement

$1 $2text of group 1, 2…
$<name>text of the named group
$&the whole match
$$a literal $ sign

Flags

gall matches
iignore case
m^ and $ apply to each line
sdot matches line breaks
uUnicode mode (\p{…}, emoji)
y“sticky” search from lastIndex

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

  1. Enter the pattern without the slashes, or load a common example.
  2. Add the flags you need, for example g for every match and i to ignore case.
  3. Paste the text: the result updates as you type.
  4. To transform the text, enable replacement and use $1 or $<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 . * + ? ^ $ { } ( ) | [ ] \ /.