Tools › Developer
Regex Tester
Test a regular expression as you type. The pattern is colour-coded and explained piece by piece, every match and capture group is highlighted in the text in matching colours and listed in a table, and a replacement is previewed.
About this tool What it's for, how to use it and an example
What it's for
Build and check a regular expression (regex): a pattern for finding text, used in code, search boxes, editors and command-line tools. You see what the pattern matches as you type, and what each part of it means in plain English, so you can tell why it matches what it does, or why it doesn’t.
For example, when a pattern for pulling dates or IDs out of a log file matches too much, paste a few sample lines to see exactly which text each match and group takes.
How to use it
Type a pattern (without the surrounding slashes) and some text to test it on, or choose one of the Examples. Everything updates as you type.
- The pattern is colour-coded: groups in their own colours, quantifiers (
*,+,{2,4}) in orange, character classes ([a-z]) in purple, escapes such as\din green, anchors (^,$,\b) in cyan and|in red. - The text shows each match underlined, and each capture group coloured as it is in the pattern.
- Explanation breaks the pattern into parts, with groups and alternatives nested inside. Point at or focus a part to mark it in the pattern; select it to select that part in the pattern box. A pattern likely to be very slow is flagged.
- Matches lists each match and what each group captured. Select a position to select that match in the text.
- Replace shows the text with every match replaced. Use
$1or$<name>for a group,$&for the whole match, and$$for a dollar sign. - The flags are remembered in this browser. Copy as /pattern/flags copies the pattern as JavaScript code.
Example
Choose Repeated words from Examples, or type this pattern with the g and i flags:
\b(\w+)\s+\1\b
and this text:
This is is a test of the the tool.
The tool reports 2 matches, with 1 group: is is and the the, each with the repeated word as group 1. The
explanation reads \1 as “The same text that group 1 matched”. The replacement $1 gives
This is a test of the tool.
Good to know
Patterns are run by your browser’s own JavaScript regex engine, so the results are exactly what JavaScript code would get. Other languages differ in places: Python, PCRE (PHP) and .NET have features JavaScript lacks, such as possessive quantifiers and inline comments. The v flag isn’t offered. Matching is stopped after 2 seconds, which catches patterns that would otherwise freeze the page (catastrophic backtracking). The table lists the first 500 matches, and at most 2,000 are found and highlighted.
Explanation
Matches
Replace
Private: this tool runs in your browser. Nothing you type, paste or choose leaves this page.
Saved you a few minutes? Say thanks with a coffee.
Something wrong with this tool, or missing from it? Report a bug or suggest a feature.