Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding credit card regexes #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

daedalus
Copy link

No description provided.

@coffeetocode
Copy link
Contributor

coffeetocode commented Sep 28, 2018

These FPd a lot in my testing.

Suggest adding lookahead and lookbehind assertions to to cut down on other types of number strings getting included (eg, 16 digits that look like a MOP in the middle of a string of 20 digits):

    "Generic MOP": "(?<=[^\\da-zA-Z.]|\\s)[3456][0-9]{14,15}(?=[^\\da-zA-Z]|\\s)",
    "Visa": "(?<=[^\\da-zA-Z.]|\\s)4[0-9]{12}(?:[0-9]{3})?(?=[^\\da-zA-Z]|\\s)",
    "MasterCard": "(?<=[^\\da-zA-Z.]|\\s)(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}(?=[^\\da-zA-Z]|\\s)",
    "American Express": "(?<=[^\\da-zA-Z.]|\\s)3[47][0-9]{13}(?=[^\\da-zA-Z]|\\s)",
    "Diners Club": "(?<=[^\\da-zA-Z.]|\\s)3(?:0[0-5]|[68][0-9])[0-9]{11}(?=[^\\da-zA-Z]|\\s)",
    "Discover": "(?<=[^\\da-zA-Z.]|\\s)6(?:011|5[0-9]{2})[0-9]{12}(?=[^\\da-zA-Z]|\\s)",
    "JCB": "(?<=[^\\da-zA-Z.]|\\s)(?:2131|1800|35\\d{3})\\d{11}(?=[^\\da-zA-Z]|\\s)"

@dxa4481
Copy link
Owner

dxa4481 commented Sep 29, 2018

Even with the lookaheads and lookbehinds I'm still getting a lot of false positives. I ran it on the Square org, which I figured would be a good candidate for CC numbers, and it fires on a lot of crypto libraries, and other unrelated things.

@pizen
Copy link

pizen commented Oct 18, 2018

Valid credit card numbers are going to be hard to identify using only a regex. I think you'd need to add some post-match processing to validate the checksum (https://en.wikipedia.org/wiki/Luhn_algorithm).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants