Weird Regular Expression Notation for Visa Credit Card
Hello,
I came across this regular expression via the site http://www.regular-expressions.info/creditcard.html I can't seem to understand it: Code:
^4[0-9]{12}(?:[0-9]{3})?$ Despite the strange syntax, this appears to work. Anyone have any thoughts on why? -Matt |
The '?:' is so that the parentheses don't generate backreferences. This is irrelevant if you are only using grep, but in a language like perl the backreferences are used to capture substrings from the match.
|
Alright, thanks for the info. I'll have to look further into what these "back-references" entail. Until now, I've never heard of them. But as you mentioned, I'm mostly just grepping for things and using them in the context of recovering data from a seized hard drive.
Thanks again. |
Beware, this egular expression is used to identify a string as a possible credit card number, however it does not verify it is a real credit card number. To do that, the algorithm is more complicated, and I doubt whether it can be done with a regular expression.
http://en.wikipedia.org/wiki/Luhn_algorithm is a starting point, more links on that page. jlinkels |
All times are GMT -5. The time now is 04:03 AM. |