Regular Expressions 101

Community Patterns

DLP Control Regex | Credit Card & SSN

0

Regular Expression
PCRE2 (PHP >=7.3)

/
(?<ssn>(?<!\d{1})\d{3}[\s-]+\d{2}[\s-]+\d{4}(?!\d{1})|(?<!\d{1})\d{9}(?!\d{1}))|(?<creditCard>(?<![0-9]{1})(?:4[0-9]{12}(?:[0-9]{3})?|\d{4}[\s-]+\d{4}[\s-]+\d{4}[\s-]+\d{4}|\d{4}\d{4}\d{4}\d{4}|(?: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}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})(?![0-9]{1}))
/
gm

Description

Regex code that can be used to group for credit card and social security number.

Submitted by Abdullah Dalgic - a year ago (Last modified a year ago)