Can a regex match valid card numbers?

2 subset 1 9/7/2025, 8:45:41 AM abstractnonsense.xyz ↗

Comments (1)

subset · 4h ago
This was a problem that was obsessing me for a couple sleepless nights...

Ordinarily, when you look up "regex for card numbers" you get a list of card provider prefixes and length constraints, but this doesn't do any validation on the check digit (calculated using the Luhn algorithm)!

Spoiler: Regex's _can_ recognise the set of valid card numbers, but the resulting regex would be exponential in the number of states for the minimal DFA (as far as I can reason).