Credit Card Number
Match 16-digit credit card numbers with optional spaces or hyphens between groups of 4.
Try it in RegexPro →Available in
Pattern
\b(?:\d{4}[\s\-]?){3}\d{4}\b (flags: g)Raw source: \b(?:\d{4}[\s\-]?){3}\d{4}\b
How it works
Examples
Input
4111 1111 1111 1111Matches
4111 1111 1111 1111
Input
4111-1111-1111-1111Matches
4111-1111-1111-1111
Input
4111111111111111Matches
4111111111111111
Common use cases
- •PCI-DSS data discovery scans
- •Detecting card numbers in logs (for masking)
- •Payment form validation
- •Data loss prevention (DLP) tools
Related patterns
ISBN-10
ValidationMatch 10-digit ISBNs, allowing optional hyphens or spaces between groups.
ISBN-13
ValidationMatch 13-digit ISBNs starting with 978 or 979, with optional hyphens or spaces.
International Phone Number (Loose)
ValidationMatch international phone numbers in a variety of loose formats including country codes, area codes, and separators.
US Phone Number
ValidationMatch US phone numbers in common formats: (555) 867-5309, 555-867-5309, 5558675309.
Related concepts
Word Boundaries: \b and \B
Concept\b matches the position between a word character and a non-word character. It keeps your regex from matching 'cat' inside 'concatenate.'
How to Match Digits in Regex
How-toUse \d for any digit, [0-9] for ASCII digits only, or {n} to match a specific count of digits. Combine with anchors for whole-string validation.
How to Match a Specific Number of Characters
How-toUse {n} for exactly n, {n,} for n or more, {n,m} for between n and m. Apply to any single token — character, class, or group.