Dont suggest me any links , I saw all million times.
I looked at many suggestions - such as Regex credit card number tests. However, I'm not primarily concerned with verifying potential credit numbers.
I want to locate (potentential) credit card numbers in a document by identifying sequences of 12 to 19 numbers (plus a few common separator characters between them). This is being discussed in, e.g., Finding or Verifying Credit Card Numbers, at which @TimBiegeleisen points. But the suggested solution results in a few false negatives. (See section "Problems..." below.)
Sample input:
[ '232625427', 'please stop check 220 2000000 that was sent 6/10 reg mail and reissu fedex. Please charge to credit card 4610 0000 0000 0000 exp 05/99...thanks, Sxxx' ]
[ '232653042', 'MARKET PLACE: Exxxx or Bxxxx-Please set husband and wife up on monthly credit card payments. Name on the credit card is Hxxxx-Jxxxx Lxxxx (Maiden name, name on policy is different) Master card number 5424 0000 0000 0000 Exp 11-30-00. Thanks so much.' ]
Much more sample input at my RegEx101.com attempt.
My regex is
[1-9](\d[ ]?[ ]*?[-]?[-]*?[:]*?[:]?){11,18}\b
Problems with my RegEx
- The 12-19 digit numbers are not matched when immediately followed by a string. It fails, e.g., on
4554-4545-4545-4545Visa
. - Longer running sequences of numbers are matched at the end rather than the beginning: For
999999999999994190000000000000
I do get9994190000000000000
instead of9999999999999941900
I am testing it at RegEx101.com.