Regular Expression Library
Browse, test and copy ready-made regex patterns for the tasks you actually do — email-ish checks, dates, log parsing and extraction.
A curated library of 36 battle-tested patterns, each with a plain-English explanation of what it
matches and where it breaks down. Search or filter by category, hit Test to run any pattern
against your own text with live match highlighting and capture groups, then copy the pattern (or
/pattern/flags) straight into your code. You can also download the whole library as JSON.
Test a pattern on your text
How to read these patterns
Every pattern above is built from the same small set of building blocks. Once you can read these, you can adapt any pattern in the library to your own data:
| Token | Meaning |
|---|---|
^ $ | Start / end of the string (with the m flag, start / end of each line). |
\b | Word boundary — a spot between a word character (\w) and a non-word character. Keeps matches from starting or ending mid-token. |
. | Any single character except newline (with the s flag, it matches newlines too). |
\d \w \s | Digit, word character (letter/digit/underscore), whitespace. Capitalised forms (\D \W \S) negate them. |
[abc] [^abc] | Character class: any one of the listed characters; ^ inside the brackets negates it. |
[a-z0-9] | Range inside a class — every character from a to z, plus digits. |
* + ? | Zero or more, one or more, zero or one (optional) of the preceding atom. |
{n} {n,} {n,m} | Exactly n, at least n, or between n and m repetitions. |
*? +? | Lazy (non-greedy) versions — match as few characters as possible instead of as many. |
(a|b) | Alternation inside a group: match a or b. |
(...) (?:...) | Capturing group (its text is available after the match) / non-capturing group (grouping only). |
(?=...) (?!...) | Lookahead: assert that what follows (or doesn’t follow) matches, without consuming it. |
(?<=...) (?<!...) | Lookbehind: assert what comes before, without consuming it. |
The flags you’ll see
JavaScript (ECMAScript) regex flags — the same engine runs in every modern browser, so patterns here behave identically to Node.js and any JS runtime:
| Flag | Effect |
|---|---|
g | Global — find all matches, not just the first one. |
i | Case-insensitive matching. |
m | Multiline — ^ and $ match line starts/ends, not just the string ends. |
s | DotAll — . also matches newline characters. |
u | Unicode — correct behaviour for non-BMP code points and \w over all letters. |
y | Sticky — match only at the current position (for incremental scanning). |
Before you copy-paste
No email regex is perfect. The full RFC 5322 grammar for addresses is enormous — quoted local parts, comments, IP-literal domains. Every practical pattern (including the two in this library) trades completeness for sanity. Use one for client-side shape checking and extraction, then confirm by email or DNS; never treat a regex match as proof that a mailbox exists.
Beware catastrophic backtracking. Nested quantifiers like (a+)+ or (\w+\s?)* can take exponential time on input that almost matches, freezing the tab. The patterns in this library avoid them, but when you adapt a pattern, test it against a long non-matching string (e.g. 10,000 as followed by !) before shipping it.
Shape ≠ validity. A pattern that matches the shape of an ISO date, a credit card or an ISBN is not validating it — each entry’s Limitations box says exactly what extra check (calendar math, Luhn, modulus) you need on top.