How to Test Regular Expressions Online
Test regular expressions against your own data. We ran five popular "common patterns" against known answers: the email pattern accepted user..dots@example.com, the date pattern accepted February 30, and the phone pattern rejected +1 numbers.
Why Test Against Your Own Data
A pattern that matches the examples you had in mind can still accept garbage and reject valid input. An online tester shows every match as you type, so you can paste real samples, add the awkward cases and watch what changes. Our Regex Tester runs the pattern in a background worker with a 2-second limit, so a catastrophic pattern such as (a+)+$ stops with a message instead of freezing the tab, and it lists every match with g, including empty ones.
Five "Common Patterns", Tested
We ran the patterns most tutorials hand out (this guide included, until now) against inputs where the right answer is known, using JavaScript's RegExp (October 14, 2026; script in our test folder):
| Pattern for | Wrongly accepted | Wrongly rejected |
|---|---|---|
Email ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ | user..dots@example.com, .lead@example.com, a@-bad-.com | josรฉ@example.com (an internationalized address, RFC 6531) |
US phone ^\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$ | (555 123-4567 (unbalanced bracket), 123-456-7890 (no US area code starts with 1) | +1 555 123 4567 |
IPv4 ^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}โฆ$ | 01.02.03.004 (leading zeros, which some parsers read as octal) | โ |
Date ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ | 2026-02-30, 2026-04-31, 2025-02-29 | โ |
The lesson is not that these patterns are useless: they are good filters for obvious typos. But a regex cannot know calendars or numbering plans. Validate dates by parsing them (a valid date round-trips), email by sending a confirmation message, and phone numbers with a library built on the official numbering data, such as Google's libphonenumber.
Capture Groups and Named Groups
Parentheses capture the text they match. (\d{4})-(\d{2})-(\d{2}) on 2026-04-15 gives groups 1-3 as 2026, 04 and 15. JavaScript also supports named groups, written (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}), which come back as match.groups.year and so on. (This guide used to print that example as live HTML, which hid the names; the angle brackets are now escaped.) Use (?:โฆ) for grouping without capturing.
Flags
gfinds every match;iignores case;mmakes ^ and $ match at line breaks;slets . match newlines.uenables full Unicode, including\p{L}for any letter (which would fix the josรฉ@ case above) and correct handling of emoji.y(sticky) matches only atlastIndex;dadds start and end indices for each group.
Debugging a Pattern
Start from the smallest pattern that matches one real example, then add one piece at a time and re-check your list of good and bad inputs. Watch for greedy quantifiers (.* runs to the last possible match; .*? stops at the first), anchors you forgot (without ^ and $ a pattern matches inside longer text), and nested quantifiers on overlapping input, which cause catastrophic backtracking. The Regex to English tool explains a pattern piece by piece.