Developer
Regex
A regular expression (regex) is a compact pattern language for finding, validating and replacing text that matches a described shape rather than a fixed string.
Updated 12 Aug 2026
Describing text by shape
Plain search finds text you already know. A regular expression finds text you can only describe: three digits, then a dash, then four digits; or any word at the start of a line followed by a colon. The engine walks the input and reports every span that fits the pattern.
The syntax you actually need
| Pattern | Matches |
|---|---|
| . | Any character except a newline |
| \d \w \s | Digit, word character, whitespace |
| [a-f] | Any one character in the range |
| * + ? | Zero or more, one or more, optional |
| {2,5} | Between two and five repeats |
| ^ $ | Start and end of the string or line |
| (...) | Capture group you can reference in a replacement |
| (?:...) | Group without capturing |
| a|b | Either alternative |
Greedy versus lazy
Quantifiers are greedy by default: they take as much as possible and give characters back only when the rest of the pattern fails. Adding a question mark makes them lazy. Matching quotes with ".*" grabs everything from the first quote to the last on a line, while ".*?" stops at the first closing quote — a difference that explains a large share of confusing regex bugs.
Do not use regex to parse HTML, JSON or CSV. Nested and quoted structures need a real parser; a pattern will look right on your samples and fail in production.
Regex Tester
Test patterns against sample text with live match highlighting.
Characteristics
- Pattern language available in almost every programming language
- Flags control case sensitivity, global matching and multiline behaviour
- Capture groups extract parts of a match for reuse
- Dialects differ — JavaScript, PCRE and POSIX are not identical
Common uses
- Validating emails, postcodes, phone numbers and identifiers
- Search and replace across a codebase or log file
- Extracting fields from unstructured text
- Routing and redirect rules in web servers
Advantages
- Extremely concise for text matching that would take many lines of code
- Portable knowledge across languages and editors
- Built into editors, grep, databases and web server configuration
- Capture groups make structured extraction straightforward
Limitations
- Hard to read and maintain as patterns grow
- Catastrophic backtracking can hang a process on hostile input
- Dialect differences break patterns moved between languages
- Unsuitable for nested or recursive formats
Examples
^\d{4}-\d{2}-\d{2}$ # ISO date
^[\w.+-]+@[\w-]+\.[\w.]{2,}$ # pragmatic email check
(\d{3})-(\d{4}) # capture two groups
\b(\w+)\s+\1\b # repeated wordFrequently asked questions
What is regex used for?
Validating input, searching and replacing text, and extracting fields from unstructured content such as logs.
Is regex a programming language?
It is a pattern language, not a general-purpose one — it describes text shapes but has no variables or control flow.
Why is my regex matching too much?
Quantifiers are greedy by default. Add ? to make them lazy, or use a negated character class.
Can regex parse HTML?
No. HTML nests arbitrarily; use a DOM parser instead.
What is catastrophic backtracking?
A pattern with nested ambiguous quantifiers can explore exponentially many paths, freezing on certain inputs.
Related terms
Character Encoding
Character encoding is the mapping between the characters people read and the bytes computers store, defining how text is turned into binary and back again.
SQL
SQL (Structured Query Language) is the standard language for defining, querying and modifying data held in relational databases.
JSON
JSON is a lightweight text-based data format commonly used to exchange structured data between applications and APIs.
Cron Expression
A cron expression is a compact string of time fields that tells a scheduler exactly when a recurring job should run.
Base64
Base64 is an encoding scheme that represents binary data using 64 printable ASCII characters so it can travel safely through text-only channels.
XML
XML (Extensible Markup Language) is a text format that describes data using nested, self-labelled tags, designed for documents and long-lived system-to-system messaging.
Related tools
Related guides
Regex Basics: Patterns You Will Actually Use
Learn regular expressions from the parts that matter: character classes, quantifiers, anchors, groups, greedy vs lazy matching, flags and the pitfalls that cause bugs.
Base64 Explained: What It Is and When to Use It
How Base64 turns binary into text, why output is about 33% larger, where padding comes from, URL-safe variants, and why Base64 is encoding rather than encryption.
What Is JSON? A Plain-English Guide
JSON explained without jargon: what it is, how the syntax works, which data types it supports, where it is used and how it differs from JavaScript objects.
Compress PDF Without Losing Quality
Honest guide to shrinking a PDF without wrecking it: Lossless (small safe savings), Compress images (re-encode photos, keep text selectable), and Rasterize (biggest savings, flattens pages). Pick the mode that matches your file.