Regular expressions people actually search for
A short, opinionated library rather than an exhaustive one: 18 expressions covering the checks and clean-ups that come up again and again. Every pattern carries worked examples that are re-run by your own browser when you open it, snippets for three languages, and a note when the expression can be made slow by hostile input.
If you know what you want to match but not what to call it, paste an example into Match your own text above the list. Every pattern in the library runs against it and the list reorders to put the ones that hit first.
Validation
9Answer yes or no about a whole string — is this an email, a UUID, a semver tag? Anchored at both ends, so a partial hit does not count.
Extraction
5Pull every occurrence of something out of a larger body of text: links in a document, keys in a JSON blob, quoted strings in a config.
Replace
4Find the parts you want to rewrite — runs of whitespace, non-digits, HTML comments — so a single `replace` call cleans the string up.
Regex for Valid Email Address
/^[^\s@]+@[^\s@]+\.[^\s@]+$/i
Regex for URL Slug
/^[a-z0-9]+(?:-[a-z0-9]+)*$/
Regex for Strong Password
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z\d]).{12,}$/
Regex for UUID v4
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
Regex for IPv4 Address
/^(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$/
Regex for Hex Color
/^#?(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
Regex for Semantic Version
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/
Regex for Credit Card Number Format
/^(?:\d[ -]*?){13,19}$/
Regex to Extract URLs
/https?:\/\/[^\s"'<>]+/gi
Regex to Extract HTML Tags
/<\/?[A-Za-z][^>]*>/g
Regex to Extract JSON Keys
/"([^"]+)"\s*:/g
Regex to Extract Quoted Text
/"([^"\\]*(?:\\.[^"\\]*)*)"/g
Regex to Extract Markdown Links
/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g
Regex to Replace Repeated Whitespace
/\s+/g
Regex to Strip Non-Digits
/\D+/g
Regex to Collapse Blank Lines
/\n{3,}/g
Regex to Remove HTML Comments
/<!--[\s\S]*?-->/g
Regex with Nested Quantifiers
/^(a+)+$/
Why some patterns are flagged
A regular expression with nested quantifiers — (a+)+ is the classic — can take exponential time on an input that almost matches, because the engine retries every way of splitting the string before giving up. If that expression runs on user input, a short crafted string can pin a CPU core. That is catastrophic backtracking, and the denial-of-service it enables is called ReDoS.
1 of the 18 patterns here are flagged. Use Hide backtracking risks in the filters when you are picking something to run against untrusted input, and reach for a real parser when the format is genuinely nested — a regex cannot match balanced brackets at all.