Feedback

Regex for credit card numbers (digits)

Example pattern below—edit it or paste your own. All processing runs in your browser. For Python’s re module, switch flavor in the tool.

Flavor

Standard `RegExp` for explanation and preview.

g i m s u y d v (JavaScript)
Card 4532 1488 0343 6467 or 4532148803436467 (sample only).

Plain-English explanation

Flavor: JavaScript RegExp

Flags: g (find all matches)

a word boundary Then Match (non-capturing): Match digit character (0–9), repeated exactly 4 times. Then Match one character from: the character "-", whitespace character, optional, repeated exactly 3 times. Then Match digit character (0–9), repeated between 1 and 7 times. Then a word boundary

More examples

Back to RegExplain