Free Tools
By Fadhil Abdulla

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 $1 in replacements
  • (?<year>\d{4}) — named group, available as $<year>
  • (?:abc) — group without capturing
  • cat|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.

Regex Tester | JSON Formatter | URL Encoder | TRN Validator | All free tools

Keep reading

More from Pyalm

Oct 16, 2026

How to Format and Validate JSON (and Fix the 6 Most Common Errors)

Why JSON breaks, how to read a validator's error message, and a quick routine for pretty-printing, minifying and fixing JSON from APIs, logs and config files.

Oct 16, 2026

How to Compare Two JSON Files (Without Drowning in Diff Noise)

Text diffs flag reordered keys and whitespace as changes. Here's how a structural JSON comparison works, and how to use it to review API changes, configs and migrations.

Oct 16, 2026

URL Encoding Explained: %20, + and When to Encode

What percent-encoding is, why spaces become %20, the difference between encodeURI and encodeURIComponent, and how to avoid double-encoding bugs.

Oct 16, 2026

Unix Timestamps Explained: Epoch Time, Seconds vs Milliseconds and Time Zones

What epoch time is, why it's the standard way to store dates, how to tell seconds from milliseconds, and how to avoid the time-zone bugs it causes.

Oct 16, 2026

Minify vs Beautify: What Code Minification Does and When to Use It

How minifying JavaScript, CSS and HTML shrinks files, how much it really saves, and when to beautify minified code to debug it.

Oct 16, 2026

Why You Should Test with Fake Data (and How to Generate It in Seconds)

Using real customer data in development is a privacy risk; using 'test123' hides bugs. Here's how realistic fake data helps — with regional formats for the UAE, India, US and UK.

Try the free Regex Tester

Pyalm builds custom software, APIs and integrations for businesses in India and the UAE. We made these developer tools for our own team — use them free, and talk to us when you need something built.

Open Regex Tester See custom software All free tools