Regex Tester
Test a regular expression as you type: see every match and group highlighted, replace and split text, get each part explained, and copy the pattern for six languages.
- Free, no sign-up
- Runs in your browser
- Sources cited
JavaScript syntax, without the surrounding slashes.
- ISO date (YYYY-MM-DD)
- Email address (simple)
- Web address
- US phone number
- US ZIP code
- IPv4 address
- Hex color
- UUID
- Time, 24-hour
- Trailing spaces
- Repeated words
Matches in the text
Invoice 2041 was issued on 2026-03-09 and paid on 2026-04-15. The next review is due 2026-10-01; the old date 15/04/2026 is not ISO.
Match details
| # | Match | Position | Group |
|---|---|---|---|
| 1 | 2026-03-09 | 27–37 |
|
| 2 | 2026-04-15 | 50–60 |
|
| 3 | 2026-10-01 | 85–95 |
|
What the pattern means
(?<year>Start of the group named “year”, which is captured\dA digit, 0 to 9{4}Exactly 4 times)End of the group-The text “-”(?<month>Start of the group named “month”, which is captured\dA digit, 0 to 9{2}Exactly 2 times)End of the group-The text “-”(?<day>Start of the group named “day”, which is captured\dA digit, 0 to 9{2}Exactly 2 times)End of the group
Use it in code
JavaScript
const pattern = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/g;Python
import re
pattern = re.compile(r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})")PHP
$pattern = '/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/';PHP has no g flag: use preg_match_all for every match.
Java
Pattern pattern = Pattern.compile("(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})");C#
var pattern = new Regex(@"(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})");Go
pattern := regexp.MustCompile(`(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})`)How to use the regex tester
Write the pattern
Type the pattern without slashes, or load a common one such as a date, email address or IP address. Errors are explained as you type.
Choose the flags
Find all matches or only the first, ignore case, let ^ and $ work per line, let the dot match line breaks, and switch on Unicode or sticky matching.
Paste test text
Matches are highlighted in the text, and the details table lists each match with its position and every group, named or numbered.
Replace, split or test lines
Preview a replacement with $1 or $<name>, split text into pieces, or check which lines of a list match.
Understand it and take it with you
Read what each part of the pattern means, then copy it written for JavaScript, Python, PHP, Java, C# or Go, with notes where a language differs.
How regular expressions work
A regular expression describes a set of strings. Literal characters match themselves; character classes such as \d, \w and [a-z] match one character from a set; quantifiers such as *, + and {2,4} repeat what comes before them; groups in parentheses capture what they match so it can be used later; and anchors such as ^, $ and \b match positions rather than characters.
This tester uses your browser’s JavaScript engine, which follows the ECMAScript specification; MDN’s guide explains each feature. Other languages differ in places. Python’s re module writes named groups as (?P<name>…), and Go uses RE2, which has no lookarounds or backreferences in exchange for guaranteed linear time. The code panel converts what it can and warns about the rest.
Most engines, including JavaScript’s, try alternatives one by one and back up when a path fails. Patterns with nested quantifiers, such as (a+)+, can then take exponential time on some inputs, which OWASP describes as ReDoS. The tester runs every pattern in a background worker and stops it after two seconds, so a runaway pattern never freezes the page and you learn that it needs fixing.
Worked example
The pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) looks for ISO dates. In the example text it finds 3 matches: 2026-03-09, 2026-04-15, 2026-10-01. The first, 2026-03-09, starts at position 27, and its named groups give year 2026, month 03 and day 09.
With the replacement $<month>/$<day>/$<year>, the groups are put back in US order, so the text reads “Invoice 2041 was issued on 03/09/2026 and paid on 04/15/2026.”. The date 15/04/2026 in the same text is not matched, because the pattern needs a four-digit year first.
Understanding the result, and common mistakes
- Position
- Where the match starts and ends, counted in UTF-16 code units from zero, as JavaScript counts them.
- Did not take part
- The group is in a branch of the pattern that was not used for this match, so it has no value.
- Stopped after two seconds
- The pattern backtracks too much on this text. Remove nested quantifiers or make alternatives exclusive.
- Forgetting to escape. A dot matches any character; write \. for a literal dot, and \( for a parenthesis.
- Greedy quantifiers taking too much. .* runs to the end of the line; use .*? or a negated class such as [^"]* instead.
- Missing anchors. Without ^ and $, a pattern meant to validate a whole value also matches inside a longer one.
- Copying a pattern between languages unchanged. Escaping, flags and named groups differ; use the code panel.
Frequently asked questions
Which regex flavor does this use?
JavaScript’s, as run by your browser. The code panel adapts the pattern for Python, PHP, Java, C# and Go.
Is my test text sent anywhere?
No. Everything runs in your browser. Shared links include the pattern and settings but never the test text.
Can a regex validate an email address?
Only roughly. The preset catches typical addresses; the only real test is sending a message to it.
What does the g flag do?
It finds every match instead of stopping at the first, and makes replace change every match.
Why does my pattern freeze other sites but not this one?
Here it runs in a background worker with a time limit. Elsewhere the same pattern can block the page until it finishes.
Sources
- ECMAScript Language Specification: RegExp (Regular Expression) ObjectsEcma International · retrieved Nov 14, 2026
- Regular expressionsMDN Web Docs · retrieved Nov 14, 2026
- Regular expression Denial of Service (ReDoS)OWASP Foundation · retrieved Nov 14, 2026
- re: Regular expression operationsPython Software Foundation · retrieved Nov 14, 2026
- RE2 syntaxGoogle · retrieved Nov 14, 2026
About these results
- Patterns run in your browser. The text you test is never sent anywhere.