In C#, I would like to replace all sensitive digits and replace/mask with **** but there are some other digits I would not like to replace such as phone number which is a constant.
This is what I am doing now
String original = "this is your sensitive digit 12345 , if you have any question please call CONSTANTPHONENUMBER";
String pattern = @"[0-9]{4,}";
String result = Regex.Replace(original, pattern, "****");
the result is
this is your sensitive digit **** , if you have any question please call ****
My question is how can I exclude that CONSTANTPHONENUMBER so that it wont be replaced.
The desired result
"this is your sensitive digit **** , if you have any question please call CONSTANTPHONENUMBER"
Simplest one I could think of is to use negative lookahead surrounded by
\b(word boundary). Also with multiple exclusions: