Boring Tools

Regex Tester

Open tool

Test a regular expression against sample text and see matches highlighted.

Type a regular expression, paste some sample text, and see instantly what it matches — highlighted in the text, and listed one by one with each match's position and capture groups. Use it to check a pattern before putting it in code.

How it works

The pattern and the checked flags are handed to your browser's own JavaScript regex engine (new RegExp(pattern, flags)), so results are exactly what RegExp would give you in JavaScript. The engine re-runs every time you change the pattern, a flag, or the test text.

With the g flag on, every match in the text is found. With it off, only the first match is reported, like a single exec() call.

How to use it

  1. Type your pattern in the Pattern box. Enter just the pattern — no surrounding slashes, and no flags at the end.
  2. Tick the flags you need (see below). Global is on by default.
  3. Paste the text you want to test into Test string.
  4. Read the Highlighted matches box to see what was matched, and the Matches list for the details of each hit.
  5. If a red message appears, the pattern itself is invalid — fix it and the results return.

Options & controls

Inputs

Pattern
The regular expression, written the way you would inside /…/ in JavaScript, for example \d+ or (\w+)@(\w+)\.com.
Test string
The text to search. It can be several lines long; line breaks are kept.

Flags

Each flag is a checkbox. Combine as many as you like.

g (global)
Find every match, not just the first. On by default.
i (case-insensitive)
Treat upper and lower case as the same, so cat matches Cat and CAT.
m (multiline)
Make ^ and $ match at the start and end of each line, instead of only at the start and end of the whole text.
s (dot matches newline)
Let . match line-break characters too, so a pattern like a.*b can span several lines.

Page controls

Reset
In the title row. Clears the pattern and the test string and restores the default flags (only g ticked).

Reading the results

What you see

Highlighted matches
Your test text with every match marked in yellow. Shows "Nothing to test yet." until you enter some text.
Matches
Appears once there is a valid pattern. Says "No matches" or lists each hit.
Match N: “text” at index i
The matched text and its zero-based position in the test string (the first character is index 0).
Group N
The text captured by each numbered ( ) group in that match. "(no match)" means the group did not take part — for example, it sat in an alternative that was not used.
Error message
The browser's description of what is wrong with the pattern, such as an unterminated group or a nothing-to-repeat quantifier.

Tips & guidelines

  • Test against text that should not match as well as text that should. A pattern that highlights everything is usually too loose.
  • Only the first match is shown when g is off — if you expected several hits and see one, check that flag first.
  • Remember to escape characters that have a special meaning when you mean them literally: . * + ? ( ) [ ] { } | \ ^ $.
  • If you are new to regular expressions, try the Regex Builder tool, which assembles a pattern from plain-English blocks.

Limits

  • This is the JavaScript regex flavour. Features from other languages — possessive quantifiers, inline flags like (?i), Python's (?P<name>…) — may fail or behave differently.
  • Only the g, i, m and s flags are offered. Unicode (u), sticky (y), indices (d) and v flags cannot be turned on.
  • Named groups work in the pattern but are shown by number, not by name.
  • A pattern with nested repeating groups against long text can take a very long time to evaluate ("catastrophic backtracking") and may make the tab unresponsive.

Saved in your browser

Nothing. The pattern, flags and text exist only on the page.

← All documentation