I have been tasked with going through a large list of string values, and removing any sign of credit cards. So, if, within the string, I find anything that matches (where n = numerical):
nnnn nnnn nnnn nnnn (4 x 4 numerical)
nnnnnnnnnnnnnnnn (16 numerical)
nnnn-nnnn-nnnn-nnnn (Hyphened)
nnnn nnnnnn nnnn (American express?)
nnnnnnnnnnnnnn (AX, no spaces)
nnnn-nnnnnn-nnnn (AX, Hyphened)
I need to replace that part of the string with [CARD NUMBER REMOVED]
So,
"Client called and gave credit card details as 1234123412341234, exp 1201, and will be booked next week"
would become:
"Client called and gave credit card details as `[CARD NUMBER REMOVED]`, exp 1201, and will be booked next week"
I'm thinking RegEx would FIND this, but I have zero regex experience, and there are many patterns. And, how do I replace that portion?
I could write something that iterates through each char and does some rule checking, but that seems hacky.
Any ideas?
I am trying this:
const string pattern = @"^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$";
const string replacement = "[CARD DETAILS REMOVED]";
var rgx = new Regex(pattern);
string cleansedText = rgx.Replace(UncleansedText, replacement);
return cleansedText;
But it doesn't seem to find a match in this:
"1234610008918730^^9-11^^Code 064^"