Regex Cheat Sheet with Real Examples (Emails, Phones, Dates, UAE TRN)
A practical regular expression cheat sheet — the syntax you actually use, plus tested patterns for emails, UAE and Indian phone numbers, dates and tax numbers.
Editorial disclosure: Pyalm publishes and maintains the products and free tools discussed on this site. Regulatory statements are linked to primary sources where applicable. No independent professional review is claimed unless a reviewer is explicitly named.
Regular expressions look cryptic, but most real-world patterns use a small set of building blocks. This cheat sheet covers that core syntax, then shows tested patterns you can paste straight into the free Regex Tester and adapt.
The building blocks
| Pattern | Matches |
|---|---|
. |
Any character except a newline |
\d \w \s |
A digit · a word character (letter, digit, _) · whitespace |
\D \W \S |
The opposite of each |
[abc] |
One of a, b or c |
[^abc] |
Any character except a, b or c |
[a-z0-9] |
A range |
^ $ |
Start · end of the string (or line, with the m flag) |
\b |
A word boundary |
Quantifiers
| Pattern | Means |
|---|---|
a* |
Zero or more |
a+ |
One or more |
a? |
Optional (zero or one) |
a{3} |
Exactly 3 |
a{2,5} |
Between 2 and 5 |
a+? |
Lazy — as few as possible |
Quantifiers are greedy by default: <.+> on <b>bold</b> matches the whole string. Add ? to make it lazy and match just <b>.
Groups and alternation
(abc)— capture group, available as$1in replacements(?<year>\d{4})— named group, available as$<year>(?:abc)— group without capturingcat|dog— either side(?=x)/(?!x)— lookahead: followed / not followed by x(?<=x)/(?<!x)— lookbehind: preceded / not preceded by x
Flags
g find all matches · i ignore case · m ^ and $ match per line · s dot matches newlines · u full Unicode.
Ready-made patterns
Email (practical, not RFC-perfect)
[\w.+-]+@[\w-]+\.[\w.-]+
Good for finding emails in text. Never rely on regex alone to validate sign-up emails — send a confirmation link.
UAE mobile number
(?:\+971|00971|0)?5[024568]\d{7}
Matches +971501234567, 0559876543 and 00971521112233.
Indian mobile number
(?:\+91[\s-]?)?[6-9]\d{9}
Date in YYYY-MM-DD with named groups
(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])
It checks the shape, not the calendar — 2026-02-31 still matches. Validate real dates in code.
UAE TRN (15 digits starting with 100)
\b100\d{12}\b
For a full format check use the UAE TRN Validator.
Indian GSTIN
\b\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]\b
Replacing with groups
Reformat dates from YYYY-MM-DD to DD/MM/YYYY with the date pattern above and the replacement $<day>/$<month>/$<year>. The Regex Tester previews the result before you put it in code.
Avoid catastrophic backtracking
Nested quantifiers like (a+)+ or (\w+\s?)$ can take exponential time on inputs that almost* match — enough to freeze a browser or take down a server. Keep patterns specific, avoid quantifying a group that already contains a quantifier, and anchor patterns where you can.
Beyond regex
Regex is perfect for well-defined formats. For messy real-world documents — invoices, receipts, contracts — where layouts vary, AI document extraction is far more robust than ever-growing patterns. Pyalm builds AI document-processing pipelines that read documents and push structured data into your systems.
Related free tools
Regex Tester | JSON Formatter | URL Encoder | TRN Validator | All free tools