Download Cheat sheet PDF 12 pages · syntax, editors, patterns, Unicode, performance, debugging
Blog

Articles on regex.

Practical answers to the regex questions developers actually search for. 39 articles and counting.

Patterns · 9 articles

How to match an email address with regex (and why no regex is truly perfect)

The complete guide to matching email addresses with regex in JavaScript, Python, and PCRE. Includes the pattern, edge cases, and why no regex is truly perfect.

How to match a URL with regex

How to match http and https URLs with regex — a practical pattern, what it catches, and when to use a URL parser instead.

How to validate phone numbers with regex

Phone number regex patterns for US, international, and E.164 format. Why phone validation by regex is harder than email.

Regex to match a date — every common format

Regex patterns for ISO dates, US dates (MM/DD/YYYY), European (DD/MM/YYYY), and date-times. Including leap year warnings.

How to validate an Aadhaar number with regex (Python)

Step-by-step: validate Aadhaar format with regex, then verify the Verhoeff checksum in Python.

Extract Indian PAN numbers from a document — Python and JavaScript

Use regex to find all PAN card numbers in a document or chat log. Code in Python and JavaScript.

Match dates in different formats — ISO, US, EU, and more

Date regex patterns for ISO, MM/DD/YYYY, DD/MM/YYYY, and natural-language formats.

Extract URLs from a block of text with regex

A practical URL-matching regex that covers https, http, and bare domains.

Strict IPv4 address regex (with octet range validation)

A regex that rejects 256.1.1.1 and other out-of-range octets, plus when to skip strictness.

How-to · 16 articles

How to extract numbers from text with regex

Extract integers, decimals, negative numbers, and currency from any string using regex. Examples in JavaScript and Python.

How to escape special characters in regex

How to escape regex metacharacters when you want to match them literally. Reference table and language-specific helpers.

Regex to match anything between two strings

How to match text between two specific strings using regex. Multiple approaches with greedy, lazy, and lookaround alternatives.

Regex match anything except specific characters

How to match any character except specific ones with regex using negated character classes. Examples with quotes, brackets, and patterns.

Remove emojis from a string with regex

Strip emojis from user input in JavaScript, Python, and Go.

Extract @mentions and #hashtags from a tweet

Quick regex recipes for parsing social-media-style markup in any language.

Parse a CSV line — when regex works and when it doesn't

Why regex for CSV is mostly wrong, but a few patterns that do work for simple cases.

Find duplicate consecutive words with regex

A classic regex use of back-references — and a couple of subtle gotchas.

Strip HTML tags from a string with regex

Quick HTML-tag-strip recipes, and why you should usually use a parser instead.

Mask all but the last 4 digits of a credit card number

Use regex to redact card numbers in logs and displays — show only the last 4 digits.

Extract international phone numbers from text

A loose regex that catches phone numbers in multiple countries, plus when to use libphonenumber instead.

Replace multiple spaces with a single space

A one-line regex that normalizes whitespace, plus what to watch for.

Match quoted strings (with escape handling)

A regex for double- or single-quoted strings that handles escaped quotes inside.

Match content between two delimiters with regex

A simple lazy regex captures content between two markers — but watch the boundary cases.

Extract the file extension from a filename with regex

Pull the extension off a path or filename, with handling for multi-part extensions.

Validate a strong password with regex

A regex for strong passwords (uppercase + lowercase + digit + symbol + length) — and why you should think twice about it.

Concepts · 7 articles

Greedy vs lazy quantifiers in regex

The difference between greedy and lazy regex quantifiers, with real examples and how to choose between them.

What does \b mean in regex?

The \b in regex is a word boundary — a zero-width assertion that matches positions between word and non-word characters. Examples and gotchas.

What does (?:) mean in regex? Non-capturing groups explained

Non-capturing groups in regex — what (?:) does, when to use it, and how it differs from a regular capturing group.

Lookahead vs lookbehind — when to use each

When to use lookahead (?=...) vs lookbehind (?<=...) in regex. Side-by-side examples, performance notes, and flavor support.

Regex backreferences — match the same text twice

How regex backreferences work — match the same text again, find repeated words, validate matching tags, and more.

Regex match multiline — the dotall flag explained

Why "." doesn't match newlines by default, and how to fix it with the dotall flag (s) in JavaScript, Python, and other languages.

Regex named groups in JavaScript and Python

How to use named capture groups in regex. Syntax differences between JavaScript and Python, how to access matched values, and when to use named over numbered.

Performance · 2 articles

Why is my regex slow? Common causes and fixes

Why some regex patterns are slow or hang on certain inputs. Diagnosing nested quantifiers, catastrophic backtracking, and performance fixes.

What is ReDoS? Regex denial-of-service explained

ReDoS is a class of attack where a malicious regex pattern or input causes exponential CPU consumption. How it works, how to detect, and how to prevent.

Reference · 5 articles

Regex case insensitive — in every language

How to make a regex case insensitive in JavaScript, Python, Java, PHP, Go, and other languages. Including inline case modifiers.

Python regex vs JavaScript regex — 7 differences that matter

The seven key differences between Python and JavaScript regex flavors: named groups, lookbehinds, flags, raw strings, and more.

Every regex flag in every language — full reference

Complete reference of regex flags in JavaScript, Python, Java, Go, Ruby, and PCRE. Includes case insensitive, multiline, dotall, sticky, and Unicode.

The pocket regex cheat sheet (bookmark this)

One-page regex reference: anchors, character classes, quantifiers, groups, lookarounds, flags.

10 more common regex mistakes (and how to fix them)

Subtle bugs developers make with regex — greedy vs lazy, anchors, escaping, Unicode, and more.