Regex Tester

Test a regular expression against sample text and see every match.

Developer Tools Free, no sign-up Runs in your browser

Regex Tester tool

No surrounding slashes needed.

Flags

Highlighted matches

Match details

#MatchIndexGroups
Common tokens
\d \w \sDigit, word character, whitespace
\D \W \SThe opposite of each
. Any character except a newline
^ $Start and end of the text, or of a line with the m flag
\bWord boundary
* + ?Zero or more, one or more, optional
{2,5}Between two and five times
[abc] [^abc]Any of these, none of these
(x) (?:x)Capture group, non-capturing group
(?<name>x)Named capture group
a|bEither a or b

About the Regex Tester

Regex Tester lets you write a regular expression and immediately see what it matches in a block of sample text. Matches are highlighted as you type, so building a pattern becomes a conversation with the text rather than a guessing game followed by a run.

Below the highlighted text, every match is listed with its position and its capture groups. Capture groups are the bracketed parts of a pattern, and they are where most of the real work happens: a pattern that matches a date is useful, but a pattern that captures the day, month and year separately is what lets you reformat it.

All the standard JavaScript flags are available as switches: global for every match rather than the first, case-insensitive, multiline so that the start and end anchors apply per line, dot-all so a full stop also matches newlines, unicode, and sticky. Invalid patterns produce the browser's own explanation rather than silence, and a cheat sheet of common tokens sits alongside for when you cannot remember whether it is \d or \w you want.

How to use the Regex Tester

  1. Enter a patternType the regular expression. You do not need the surrounding slashes.
  2. Set the flagsGlobal, case-insensitive, multiline and the rest are toggles beside the pattern.
  3. Paste sample textMatches highlight as you type in either box.
  4. Inspect the matchesEach match is listed with its index and any capture groups it produced.

Features

  • Live highlighting of every match
  • All standard flags as switches
  • A list of matches with position and capture groups
  • Named capture groups shown by name
  • Clear message when a pattern is invalid
  • Guard against patterns that match an empty string forever
  • A short reference of common tokens on the page

Who uses this tool

The regex tester is used by writers, developers, students, marketers and anyone else who needs the job done once without installing software. Common cases include:

  • Building a validation pattern for a form field
  • Extracting values from log lines or scraped text
  • Checking what a pattern from a code review actually does
  • Learning regular expressions against text you understand
  • Preparing a pattern for the Find and Replace tool

Frequently asked questions

Which flavour of regular expression is this?

JavaScript, because the matching is done by your browser's own engine. That covers the great majority of common syntax, but a few features found in other languages, such as lookbehind in older browsers or possessive quantifiers, may behave differently.

Why does my pattern only find the first match?

The global flag is off. Without it, the engine stops after the first match. Switch on g to find every occurrence.

What is the difference between multiline and dot-all?

Multiline makes the caret and dollar anchors apply at the start and end of each line rather than the whole text. Dot-all makes a full stop match newline characters too. They solve different problems and are often confused.

What are capture groups and named groups?

A bracketed part of a pattern captures what it matched so you can use it afterwards. Naming one with the syntax for named groups makes the result readable, which matters when a pattern has five groups and you cannot remember which is which.

Why does the tool warn about a pattern matching an empty string?

A global pattern that can match nothing will loop forever on the same position. The tool detects that and stops, so your browser tab does not freeze.

Is my sample text sent anywhere?

No. Matching runs in your browser, so log extracts and real data stay on your device.

If the regex tester is not quite what you need, these other free tools solve closely related problems.

Find and Replace Text

Replace text everywhere at once, with case options and regex support.

Text Tools Use tool

Text Cleaner

Tidy messy pasted text: extra spaces, empty lines, breaks and special characters.

Text Tools Use tool

JSON Formatter

Pretty-print and validate JSON, with the exact line and column of any error.

Developer Tools Use tool

URL Parser

Split a URL into every component, including a table of query parameters.

Developer Tools Use tool

Text Diff Checker

Spot every added, removed and unchanged line between two versions.

Text Tools Use tool