Regex Examples for Emails, Phone Numbers and Dates (Copy, Test and Adapt)

Most people do not want to learn regular expressions. They want a regex for email validation, a pattern that finds phone numbers in a pasted list, or a quick way to turn 26/11/2026 into 2026-11-26. This post gives you working regex examples for exactly those jobs, explains what each part does so you can adapt it, and shows how to try them safely on your own text.
All patterns here use the JavaScript flavour, which is what the DoraPDF Regex Tester runs. They also work, with little or no change, in most editors, Python and PHP.
How to test a pattern before you use it
- Open the Regex Tester.
- Type the pattern into Pattern (without the slashes around it).
- Add Flags if needed:
ifor case-insensitive,mso^and$match at the start and end of each line. The tester always searches globally, so every match is shown, not just the first. - Paste sample text into Test text. Matches are highlighted as you type, and a table lists each match, its position (index) and the captured groups.
If the pattern has a syntax error, you see the error message instead of highlights. That makes it a good place to debug before pasting a pattern into code or a spreadsheet formula.
Regex for email addresses
Finding emails inside text
[\w.+-]+@[\w-]+(\.[\w-]+)+
[\w.+-]+one or more letters, digits, underscores, dots, plus signs or hyphens (the part before @).@the at sign.[\w-]+the first part of the domain.(\.[\w-]+)+one or more ".something" parts, sosite.ioandmail.example.co.ukboth match.
Use this to pull addresses out of a messy paste, such as an email thread or exported contacts.
Checking that a whole field is an email
^[^\s@]+@[^\s@]+\.[^\s@]{2,}$
Here ^ and $ force the pattern to cover the entire value, and [^\s@] means "anything except a space or @". It deliberately stays loose. A strict pattern that tries to follow every rule of the email standard becomes long and still rejects some real addresses. For sign-up forms, a simple check plus a confirmation email is far more reliable than a clever regex.
To check a list with one address per line, add the m flag so ^ and $ work per line.
Regex for phone numbers
Phone formats differ by country, so there is no single correct regex for phone numbers. Start from the format you actually receive.
International style (E.164-like):
\+?[1-9]\d{7,14}
An optional +, then a digit that is not zero, then 7 to 14 more digits. Good for numbers already stored without spaces, like +923001234567.
Pakistani mobile numbers:
(\+92|0)3\d{2}[- ]?\d{7}
Matches 03001234567, 0300-1234567 and +923001234567. The group (\+92|0) means "either +92 or 0", and [- ]? allows one optional hyphen or space.
US and Canada style:
\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}
Accepts (555) 123-4567, 555.123.4567 and 5551234567.
A tip that saves a lot of pain: if you need to compare or store numbers, first strip everything that is not a digit or a plus sign, then validate. That turns many formats into one.
Regex for dates
ISO format, YYYY-MM-DD:
\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])
The month group allows 01 to 12, the day group 01 to 31.
Day/month/year, DD/MM/YYYY:
(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/\d{4}
Month/day/year (US), MM/DD/YYYY: swap the first two groups.
(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01])/\d{4}
Remember what regex can and cannot do here. These patterns check the shape of a date. They will happily accept 31/02/2026, which does not exist. For real validation, parse the date in your code or spreadsheet after the regex has done the rough filtering.
Reformatting text with regex find and replace
Finding things is half the job. The other half is changing them. The Text Replacement Tool has a Regex option, and its replacement field understands capture groups written as $1, $2 and so on.
Example: convert DD/MM/YYYY dates to YYYY-MM-DD
- Paste your text into the Text Replacement Tool.
- Tick Regex.
- Find:
(\d{2})/(\d{2})/(\d{4}) - Replace with:
$3-$2-$1
26/11/2026 becomes 2026-11-26, everywhere in the text at once. The tool tells you how many replacements it made, which is a quick sanity check.
Other useful one-liners:
| Goal | Find (Regex on) | Replace with |
|---|---|---|
| Collapse double spaces | {2,} |
a single space |
| Remove spaces at the end of each line | +(?=\n) |
(empty) |
| Mask all but last 4 digits of a number | \d(?=\d{4}) |
* |
| Turn "Khan, Asad" into "Asad Khan" | (\w+), (\w+) |
$2 $1 |
Note that the Text Replacement Tool ignores letter case unless you tick Match case. For patterns made of digits and symbols that makes no difference, but keep it in mind when you work with words. The Whole words option wraps your pattern in word boundaries, which is useful for plain words but can stop symbol-based patterns from matching, so leave it off for the examples above.
Common problems and fixes
- The pattern matches too much. Quantifiers like
.*are greedy and run to the last possible match. Use a narrower class like[^,]*, or a lazy version.*?. - Nothing matches at all. Check for spaces you did not intend in the pattern, and check whether you need the
iormflag. - A dot matches everything. An unescaped
.means "any character". Write\.when you mean a literal dot, as in domain names. - Special characters in your text break the pattern. Characters like
( ) [ ] + ? * ^ $ |need a backslash to be taken literally. - Works here, fails elsewhere. Some tools use a different regex flavour. Lookbehind and named groups, for example, are not supported everywhere.
Privacy
Both tools run in your browser. Your patterns and test text stay on your device and are not uploaded, so it is fine to test against real customer lists or log files. If you need to count words or characters in the cleaned text afterwards, the Word Counter also works locally.
FAQ
What is the best regex for email validation?
A short, permissive one such as ^[^\s@]+@[^\s@]+\.[^\s@]{2,}$, followed by a confirmation email. Strict patterns reject real addresses and still cannot prove an inbox exists.
How do I make a regex case-insensitive?
Add the i flag in the Regex Tester. In the Text Replacement Tool, leave Match case unticked.
What do $1 and $2 mean in the replacement? They insert whatever the first and second bracketed groups in your pattern matched, so you can rearrange parts of the text.
Why does my date regex accept 31 February? Regex only checks the pattern of digits. Checking whether the date exists needs a real date parser.
Try the tools from this guide — free
Keep reading
Online Case Converter, Find and Replace, Lorem Ipsum and More: 6 Small Writing Tools That Save Real Time
Convert text case, clean spaces, find and replace with regex, generate lorem ipsum, preview email subject lines and posts, and convert color codes, free.
GuideFree Developer Tools Online: JSON Formatter, Regex Tester, Base64, URL Encoder, JWT Decoder, SQL and UUID
Eight small browser-based developer tools for everyday debugging: validate JSON, test regex, decode JWTs and Base64, format SQL, make UUIDs. Free.
GuideHow to Find Credible Sources for an Assignment (and Use AI Safely)
Find and evaluate credible sources for an assignment: a 5-question check, where to search, and how to verify leads from an AI study helper.