About Regex Tester
Regular expressions are quick to write and slow to get right. Testing one inside your app means running the code again for every tweak. Here you see what a pattern matches as you type: each hit is highlighted in the text, and listed with its position and capture groups.
Add a replacement and you also see the text as it would come out, using $1 or $<name> for groups. Mistakes get an explanation that says what to do, and a pattern that backtracks out of control gets stopped and named as such, which also makes this a handy place to catch a catastrophic pattern before it reaches a server.
How it works
Patterns run on your browser's own JavaScript regex engine, so results match what new RegExp() does in the same browser. Matching happens in a background worker with a limit of 1.5 seconds. If a pattern is still running then, the worker is shut down and you get a message about heavy backtracking, while the page stays responsive.
Zero-length matches, such as ^ or a*, are handled by moving the search forward by hand, because a plain loop would otherwise repeat forever. Named groups are read from the pattern and shown by name. If you paste a whole literal such as /foo\d+/gi, it is split up for you, with the pattern placed in the box and the flags switched on.
How to use Regex Tester
- Type a pattern in the top bar, or paste a
/pattern/flagsliteral. Try an example fills in a date pattern. - Tick the flags you want: g, i, m, s, u and y.
- Put your text in the Test text box, or press Upload. Matches light up and are listed on the right.
- To try a substitution, fill in Replace with, and the result appears under After replacing.
- Press Copy matches, or Download to save
regex-matches.txt.
Named groups and a date rewrite
Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Replace with: $<day>/$<month>/$<year>
Invoice 2026-03-14 was paid on 2026-04-02.
Not a date: 2026-3-1Pattern: /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/g
Matches: 2
1. "2026-03-14" at index 8 groups=["2026","03","14"]
2. "2026-04-02" at index 31 groups=["2026","04","02"]
After replacing:
Invoice 14/03/2026 was paid on 02/04/2026.
Not a date: 2026-3-1The last line stays as it was, because \d{2} needs two digits. Each match in the list on the page also shows its year, month and day under those names.
When it helps
- Building a validation pattern for a form field, with good and bad samples in the text box
- Pulling fields out of log lines by trying named groups against real output
- Previewing a find and replace across a file before running it in your editor
- Checking whether a pattern from a code review can backtrack badly on long input
Tips for a better result
- Include text that should not match. A pattern that catches every good sample is only half tested.
- Nested quantifiers such as
(a+)+are the classic cause of runaway patterns. Making the inner part more specific usually solves it. - Leave out the g flag to see only the first match, which is what a plain
.exec()or.match()call gives you in code.
Good to know
- This is JavaScript's regex flavor. Features from other engines, such as possessive quantifiers and recursion, are errors here, and Python, Go and PCRE can treat some syntax differently, so retest in your target language.
- The list on the page shows the first 200 matches, and matching stops at 2,000. Copy and Download include every match found.
- Unicode property escapes and some newer syntax depend on your browser's version and on the u flag.
- Sample text loaded through Upload is limited to 5 MB.
Questions people ask
Why does my pattern work here but not in Python?
Each language has its own engine. Named groups are a common example: Python writes (?P<name>...), and JavaScript writes (?<name>...). This page only speaks JavaScript.
What does the m flag do?
It makes ^ and $ match at each line break, not only at the start and end of the whole text. The s flag is different: it lets . match line breaks.
Why did it stop after 1.5 seconds?
The pattern is backtracking heavily on this text, usually because of nested quantifiers. On a server, the same pattern can hang a whole process, which is known as ReDoS.
How do I match a literal bracket or dot?
Put a backslash in front: \[, \(, \.. The error message for an unclosed bracket reminds you of this.
What to use next
- Find and Replace: for plain text replacement across a document
- Log Prettifier: when the goal is to read logs and not to parse them
- JSON Path Tester: when the data is JSON, where a path beats a pattern
Learn more
Last reviewed . Read our editorial policy.