Regex pattern
Credit Card Regex — free online tester
Match credit-card numbers from major networks (Visa, Mastercard, Amex, Discover) for extraction or redaction.
The pattern
\b(?:4\d{3}|5[1-5]\d{2}|3[47]\d{2}|6011)[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/gHow it works
This regex matches the shape of credit-card numbers from the four major networks, including the common space- and dash-separated visual formats. It tells you "this string looks like a card number" — not "this card number is valid". Pair it with a Luhn check (the last-digit checksum) before treating any match as a real card.
When to use it
- ▸Redact card numbers from log files and crash reports
- ▸Prevent users accidentally pasting card numbers into chat / support tickets
- ▸Pre-flight check before sending to a payment processor
- ▸Find leaked card numbers in scraped data
Tip
NEVER store or transmit a matched card number — your stack is now in scope for PCI DSS. Use this only to detect and discard.
Try it on this input
Visa: 4532 1234 5678 9010 Mastercard: 5500-0000-0000-0004 Amex: 3400 000000 00009 Discover: 6011 1111 1111 1117 Compact: 4532123456789010 Not cards: 1234, 1234567890123, just text
What this pattern doesn't catch
- ⚠Doesn't validate the Luhn checksum — use isLuhn() after extraction for true validation
- ⚠Doesn't catch JCB, Diners, UnionPay, or other regional networks
- ⚠Amex cards are 15 digits — the spacing format above matches; tighten if you only want 16-digit cards
More regex patterns
Email Regex
A practical email-validation regex that catches the 99% case without choking on every RFC edge case.
URL Regex
Extract every http(s) URL from a block of text — captures protocol, domain, path, query string, and fragment.
Phone Number Regex
Match US / Canada phone numbers in every common written format — with or without country code.
Date Regex (ISO 8601)
Match ISO 8601 dates (YYYY-MM-DD) and optionally times in any text — the format JSON APIs, databases, and logs use.
IPv4 Regex
Strictly match IPv4 addresses — rejects out-of-range octets like 256.0.0.1 that simpler patterns let through.
UUID Regex
Strict UUID pattern — validates version (1–7) and variant nibbles so random hex strings don't pass.
Full Regex Tester →
Cheatsheet · pattern builder · cross-language translation · replace · explain · history
