Regex Tester

This regex tester runs your regular expression against sample text as you type, highlights every match and lists the capture groups of each one. Toggle flags, preview a replacement, and keep the cheat sheet below at hand. Patterns use the JavaScript (ECMAScript) flavor, the same engine as your browser and Node.js.

/g
Flags
This pattern has a quantifier inside a repeated group, such as (a+)+. On some inputs it can backtrack catastrophically and take a very long time.

Matches 3 matches

Contact ada@example.com or grace.hopper@navy.mil.
Old address: alan@turing.org.uk (not monitored)
Invalid: @nobody, someone@, a@b
Match details and capture groups
#PositionMatchGroup 1 <user>Group 2 <domain>
18–23ada@example.comadaexample.com
227–48grace.hopper@navy.milgrace.hoppernavy.mil
363–81alan@turing.org.ukalanturing.org.uk

Runs in a background worker in your browser with the JavaScript RegExp engine. Your pattern and text are not uploaded.

How do you test a regex?

Type the pattern, choose flags such as g for all matches or i to ignore case, and paste some text: every match is highlighted immediately and its groups appear in a table. Try text that should match and text that should not, because a pattern that matches too much is as wrong as one that matches nothing. Results here match what JavaScript code will do.

How to use the regular expression tester

Use this regex tester online as a scratchpad: check regex ideas against real text before they go into your code.

  1. Enter the pattern between the slashes, without the slashes themselves. Errors such as an unclosed group are reported as you type.
  2. Tick flags. Without g only the first match is found, which is how RegExp.exec and String.match behave too.
  3. Paste the test string. Matches alternate between two colours so neighbouring matches are easy to tell apart.
  4. Turn on Replace to preview String.replace with $1, $<name> or $& (the whole match).

Regex cheat sheet

The most used tokens in JavaScript regular expressions. The full reference is the MDN regular expression cheat sheet, and the grammar itself is defined in the ECMAScript specification.

Characters and classes

.Any character except a line break (any at all with the s flag)
\d \DA digit 0–9 / not a digit
\w \WA word character [A-Za-z0-9_] / not one
\s \SWhitespace (space, tab, line break…) / not whitespace
[abc]One of a, b or c
[^abc]Any character except a, b or c
[a-z]A character in the range a to z
\p{L}Any Unicode letter (needs the u flag)
\. \* \\A literal dot, asterisk or backslash

Quantifiers

*Zero or more
+One or more
?Zero or one (optional)
{3}Exactly 3
{2,5}Between 2 and 5
{2,}2 or more
*? +? ??Lazy versions: as few as possible

Anchors and boundaries

^ $Start / end of input (of each line with the m flag)
\b \BWord boundary / not a word boundary

Groups and lookaround

(abc)Capture group, referenced as $1 or \1
(?<name>abc)Named group, referenced as $<name> or \k<name>
(?:abc)Group without capturing
a|ba or b
(?=abc) (?!abc)Followed by / not followed by abc
(?<=abc) (?<!abc)Preceded by / not preceded by abc

Flags

gglobalFind all matches, not just the first
iignoreCaseCase-insensitive
mmultiline^ and $ match at line breaks
sdotAll. also matches line breaks
uunicodeUnicode code points and \p{…} escapes
ystickyMatch only at lastIndex
dhasIndicesRecord start and end of groups

Regex examples

Copy any of these into the tester above and change them to fit:

PatternMatches
^\d{5}(-\d{4})?$US ZIP code, with optional +4
^#?([0-9a-f]{3}|[0-9a-f]{6})$Hex color like #fff or #1e90ff (use i)
^\d{4}-\d{2}-\d{2}$ISO date shape, such as 2026-10-18
\b(\w+)\s+\1\bA doubled word, like “the the”
^\s+|\s+$Leading or trailing whitespace (use g to trim both)
https?://[^\s/$.?#].[^\s]*A rough URL finder

Anchors matter for a regex validator: without ^ and $, \d{5} also matches the first five digits of 1234567. When you check user input, anchor the whole pattern.

JavaScript, Java, Python and PCRE

Regex flavors share most syntax but differ at the edges. This regex checker uses the JavaScript engine, so keep these differences in mind when the pattern is for another language:

  • Java (java.util.regex) supports possessive quantifiers (a++) and atomic groups, which JavaScript does not, and in Java string literals every backslash is doubled: "\\d+". Named groups use the same (?<name>…) syntax.
  • Python (re) names groups as (?P<name>…) and sets flags with arguments such as re.IGNORECASE instead of letters after a slash.
  • PCRE (PHP, many editors) adds recursion and conditionals that JavaScript lacks.
  • A leading inline modifier such as (?i), common in Java, Python and PCRE, is not supported in JavaScript. ES2025 adds only the scoped form (?i:…), which applies i, m or s to one group (see MDN: modifier), so use the flag checkboxes for the whole pattern.

Catastrophic backtracking

JavaScript's engine backtracks: when part of a pattern fails it goes back and tries other ways to split the text. With nested quantifiers such as (a+)+$, the number of ways grows exponentially with the input length, and a short string of as followed by a b can take seconds or longer. This tester runs every pattern in a background worker and stops it after 1.5 seconds, so the page never freezes, and it warns about nested quantifiers before you run them. In production code, the same pattern can stall a server, a risk known as ReDoS.

Risky:  ^(\w+\s?)*$
Safer:  ^\w+(\s\w+)*$     (each repetition must consume a word)

Comparing two versions of a long text instead of matching a pattern? The text compare tool highlights every difference.

Frequently asked questions

What is regex?

Regex (short for regular expression) is a small pattern language for describing text, used to search, validate and replace strings. For example, \d{3}-\d{4} matches "555-1234": three digits, a hyphen and four digits. Almost every programming language, editor and command-line tool supports it.

What is regexp?

Regexp is another abbreviation of regular expression, the same thing as regex. It is also the name of the regular expression object in JavaScript (RegExp) and Go (regexp package), which is why the spelling is common in documentation.

What is regex used for?

Regex is used to find, check and transform text that follows a pattern: validating input such as emails or postcodes, extracting values from logs, search-and-replace across files in an editor, splitting strings, and routing URLs in web frameworks. It is best for flat patterns; nested formats such as HTML or JSON are safer to handle with a real parser.

What does * mean in regex?

In regex, * means "zero or more of the previous item", so ab*c matches "ac", "abc" and "abbbc". It is greedy, taking as many repetitions as possible; add ? (as in *?) to make it lazy and take as few as possible. To match a literal asterisk, escape it as \*.