Regex Tester
Type a pattern and a test string to see every match, its index and its groups, with a replace preview.
Matches
| # | Index | Match | Numbered groups | Named groups |
|---|
Replace preview
How to use
- Type a regular expression, without the surrounding slashes, into Pattern.
- Tick the flags you need: g for every match, i to ignore case, m so
^and$work per line, s so.crosses line breaks, and u for Unicode code points. - Paste your text into Test string. The results update as you type.
- Read the status line and the Matches table. Each row gives the match number, its index, the matched text, the numbered groups and the named groups.
- Type a replacement into Replacement (preview) to see the text after substitution in the Replace preview box. Nothing is changed in your original text.
Worked example
The page opens with the pattern (?<year>\d{4})-(?<month>\d{2}), the flag g, and the test string Released 2024-05 and 1999-12. It finds 2 matches:
| # | Index | Match | Numbered groups | Named groups |
|---|---|---|---|---|
| 1 | 9 | 2024-05 | 1: "2024", 2: "05" | year: "2024", month: "05" |
| 2 | 21 | 1999-12 | 1: "1999", 2: "12" | year: "1999", month: "12" |
The replacement $<month>/$1 uses the named group month, a slash and group 1. The preview reads Released 05/2024 and 12/1999. The index counts from 0, so 2024-05 starts at the tenth character.
Try changing \d{4} to \d{3}. The pattern then matches 024-05 at index 10, in the middle of the number, which shows why boundaries such as \b matter.
How it works
This page uses the regular expression engine built into your browser, so the dialect is the JavaScript one defined in the ECMAScript specification. The MDN regular expressions guide is the best reference for the syntax. This dialect differs from PCRE, Python and .NET in places, for example in the syntax for named groups and in having no possessive quantifiers or atomic groups, so a pattern copied from another language may need changes.
The engine tries to match at each position from left to right, and quantifiers such as * and + are greedy by default. In <b>one</b><b>two</b>, the pattern <b>.*</b> matches the whole string, while the lazy form <b>.*?</b> matches only <b>one</b>. Engines like this one use backtracking, which can take exponential time on patterns with nested repetition, such as (a+)+$ against a long run of a's followed by another character. The page runs each test in a background worker and stops it after one second, so a runaway pattern reports a timeout instead of freezing the tab. The OWASP page on ReDoS explains why this matters for server code.
Indexes are in UTF-16 code units, so an emoji counts as two positions, with or without the u flag. The flag changes what the pattern matches, not how positions are counted. Empty matches are listed too, and the search steps forward after each one so it always finishes. At most 1000 matches are listed, but the count and the preview cover all of them.
Common mistakes and edge cases
- Forgetting to escape. A dot matches any character. To match a full stop, write
\.. The same goes for( ) [ ] { } + * ? | ^ $ \. - Expecting g to be on. Without g only the first match is found. The box is ticked by default here, but code that uses the pattern needs the same flag.
- Greedy surprises.
.*consumes as much as it can. Use.*?or a more specific class such as[^"]*. - Anchors without m.
^and$match only the start and end of the whole string unless m is on. - Emoji and accents. Without u,
.matches half of an emoji. With u it matches the whole character. - Replacement dollar signs. A literal dollar in the replacement must be written
$$. - Parsing HTML. Regular expressions are poor at nested markup. Use a parser for anything beyond simple extraction.
Frequently asked questions
Why does my pattern work here but not in Python or PHP?
The dialects differ. Named groups are written (?<name>...) here and (?P<name>...) in Python, and some features have different syntax or are missing.
What is the difference between a numbered and a named group?
Both capture text in parentheses. A named group can be read by its name, which survives edits to the pattern. Numbered groups shift if you add a group earlier.
What does "not matched" mean in the groups column?
The group is part of an alternative or an optional part that did not take part in this match, so it has no value.
Is my text sent anywhere?
No. Matching runs in a worker inside your browser.
Related tools
- Diff Checker to compare text before and after a replacement.
- Case Converter for case changes that do not need a pattern.
- HTML Entity Encoder and Decoder for escaping characters that a pattern might match.
- Cron Builder & Explainer, another tool where a precise pattern syntax matters.