Regex basics
| Pattern | Matches |
|---|---|
\d | Any digit 0–9 |
\w | Letter, digit or underscore |
\s | Space, tab or line break |
. | Any character except a line break |
+ / * / ? | One or more / zero or more / optional |
{3} | Exactly three times |
^ / $ | Start / end of the text (or line with m) |
( ) | Capture group |
[abc] | Any one of a, b or c |
Useful patterns
- Pakistani mobile number:
^03\d{2}-?\d{7}$ - CNIC number:
^\d{5}-\d{7}-\d$ - Simple email check:
^[^\s@]+@[^\s@]+\.[^\s@]+$ - Date as YYYY-MM-DD:
^\d{4}-\d{2}-\d{2}$
Flags
g finds every match instead of the first, i ignores upper and lower case, m makes ^ and $ work per line, s lets . match line breaks and u enables full Unicode.
Replacements
In the replacement box, $1 inserts the first group, $<name> a named group and $& the whole match. For example, pattern (\d{4})-(\d{2})-(\d{2}) with replacement $3/$2/$1 turns 2026-10-28 into 28/10/2026.
This tester uses JavaScript regex. Python, PHP and Java are very similar but differ in some advanced features.