Regex Tester

Test a regular expression against your text.

loading Regex Tester
About this tool

What is a regex tester?

A regular expression (regex) is a short pattern that describes text: \d{4}-\d{2}-\d{2} finds dates, ^\S+@\S+$ roughly finds email-shaped lines, <b>.*?</b> finds bold tags. They are used for validation, search and replace, log parsing, routing rules and scraping, and they are famously hard to get right on the first try. A regex tester lets you type the pattern and a sample text side by side and see at once what it matches, where, and what each group captured.

This one uses your browser's own JavaScript regular expression engine, the same one that runs RegExp, String.match and String.replace in Node.js and in front-end code. That means the results are exact for JavaScript and TypeScript. Other languages (Python, PCRE in PHP, Java, .NET, Go) share most of the syntax but differ in details such as lookbehind, named groups ((?P<name>...) in Python), possessive quantifiers and Unicode classes, so test those patterns in the target language too.

For every match the tool shows its position in the text, the matched value, the numbered captures and the named groups, each with its start and end index. Below that it draws a diagram of the pattern and generates a sample string that the regex accepts, which helps to understand what you wrote. Neither the pattern nor the text is uploaded, saved or put in the address bar: only the flag choices are remembered.

How to test a regular expression online

  1. Type or paste the pattern in Regex to test, without the slashes. The page opens with a date pattern and a sample text, so you can see how the results look.
  2. Write or paste the text in Text to match. The matches update a moment after you stop typing.
  3. Tick the flags you need. Global search (g) is on by default and finds every match, not only the first. The others are ignore case (i), multiline (m, so ^ and $ work on each line), dot matches newline (s), Unicode (u) and Unicode sets (v). Hover a flag to read what it does.
  4. Read the Matches table: position, value, captures and groups. The counter above it says how many matches there are, and a message tells you when there are none. At most the first 10,000 matches are shown.
  5. If the pattern is invalid, the box shows Invalid regex followed by the reason in plain words, such as a missing parenthesis.
  6. Copy the regex as a literal (/pattern/flags) to paste into code, copy the matched values, or copy the generated sample. The link to the cheatsheet opens the regex reference.

Examples

Dates with named groups

Pattern (\d{4})-(?<month>\d{2})-(?<day>\d{2}) on Release 2026-11-21, patch 2026-12-03. with the g flag finds two matches:

PositionValueCapturesGroups
82026-11-211 = 2026, 2 = 11, 3 = 21month = 11, day = 21
262026-12-031 = 2026, 2 = 12, 3 = 03month = 12, day = 03

Without g only the first row appears.

Greedy against lazy

On the text <b>a</b> e <b>b</b>, the pattern <b>.*</b> returns a single match that spans everything, from the first <b> to the last </b>, because .* takes as much as it can. Adding a question mark, <b>.*?</b>, takes as little as it can and returns two matches: <b>a</b> and <b>b</b>.

Multiline changes what ^ and $ mean

On two lines, ana@site.com and bob@x.com, the pattern ^\w+@\w+\.com$ finds nothing, because ^ and $ only match at the very start and end of the whole text. Tick the multiline flag (m) and both lines match.

Lookbehind to capture only a number

In Total R$ 150,50 e R$ 20, the pattern (?<=R\$ )\d+(?:,\d{2})? returns 150,50 and 20, without the R$ prefix. The diagram cannot draw lookbehind, and the tool says so, but the matches are still computed.

Common errors and how to fix them

  • Invalid regex: a group is not closed, add the missing ")": you wrote (a and never closed it. Add the ), or escape the parenthesis as \( if you meant the character.
  • A quantifier has nothing before it to repeat: *a, + or ? at the start of a pattern or group. Put the character to repeat first, or escape it: \*.
  • The pattern ends with a lone "\": escape the backslash as \\, or finish the escape sequence.
  • A reference \k points to a group that does not exist: the name in \k<name> must match a (?<name>...) group, and group names cannot be repeated.
  • An escape is not valid with the current flags: with u on, unknown escapes are errors. Remove the flag, or write the escape correctly.
  • \p{L} finds the text "p{L}": Unicode property classes need the u flag. Turn it on and \p{L}+ matches whole words with accents.

Frequently asked questions

How do I test a regex in JavaScript?

Paste the pattern and a sample text here. The tool runs the same engine as new RegExp(pattern, flags), so what matches here matches in your code. Use Copy regex to take the literal with its flags.

What do the regex flags g, i, m, s, u and v mean?

g finds all matches, i ignores case, m makes ^ and $ work per line, s lets . match line breaks, u enables full Unicode and v is its upgraded mode with set operations. When both are ticked, u is used.

Why does my regex match too much?

Quantifiers such as * and + are greedy. Add ? after them (.*?) to make them lazy, or use a more specific class such as [^<]* instead of .*.

What is the difference between a capture and a named group?

A capture is a pair of parentheses numbered from 1; a named group, (?<name>...), can also be read by its name. Both appear in the results with their positions. To use (?:...) without capturing, see the cheatsheet.

Can I compare the result with another version?

Yes. Paste the text before and after your replacement in the text diff. To sort, filter or number lines with a regex use the line tools.

Report a problem