plain/devtools home

Regex tester

Write a JavaScript regular expression and see every match highlighted as you type.

tool 04 of 12 []
all shortcuts ?

regex-testersampless sample
Flags
Highlighted matches

Uses your browser's own RegExp engine (ECMAScript), in a background worker. A run that takes longer than 1 second is stopped, so a pattern that backtracks catastrophically cannot freeze this tab.

never leaves your browser

How to use it

  1. Type your pattern without the surrounding slashes, and put flags (g, i, m, s, u, y, d, v) in the Flags box.
  2. Matches are highlighted in the test string and listed below with their position, numbered groups and named groups.
  3. Add a replacement to preview a String.replace result. Use $1 for a numbered group, $<name> for a named group and $& for the whole match.
  4. Without the g flag only the first match is reported, exactly as in JavaScript.

Examples

Select an example to load it into the tool.

  • Emails(?<user>[\w.]+)@(?<host>[\w.-]+)
  • ISO dates(\d{4})-(\d{2})-(\d{2})
  • Invalid (unclosed group)(abc

Frequently asked questions

Which regex flavor is this?

JavaScript (ECMAScript). It is close to PCRE but not identical: there is no possessive quantifier or atomic group, lookbehind is supported in modern browsers, and named groups use (?<name>...). Test patterns for Python or PCRE in that language.

What do the flags mean?

g finds all matches, i ignores case, m makes ^ and $ match at line breaks, s lets . match newlines, u enables full Unicode, y sticks to lastIndex, d records match indices and v enables set notation (newer browsers).

Why does my pattern match an empty string everywhere?

Patterns such as a* can match zero characters. The tester advances one character after an empty match to avoid looping, and empty matches are listed but not highlighted.

Is my test text uploaded?

No. The pattern and text stay in your browser and nothing is sent over the network.

What is catastrophic backtracking?

Nested quantifiers such as (a+)+ can take exponential time on certain inputs. If the page hangs, reload it and rewrite the pattern with anchors or atomic-style constructs such as lookahead with a backreference.

Related tools

esc
↑↓ move↵ open? all shortcuts

Keyboard shortcuts

Cmd or Ctrl shortcuts always work.
Everywhere
Everywhere
Open the command palette
CtrlK
Open the palette (outside a text field)
/
Show these shortcuts
?
Toggle light and dark theme
t
Go home
gh
Go to all tools
gt
On a tool page
On a tool page
Run the main action
Ctrl↵
Copy the output
c
Load the next sample
s
Focus the input
i
Leave a text field
Esc
Previous or next tool
[]
In the palette
In the palette
Move the selection
↑↓
Open the selected item
↵
Close
Esc