using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
StringBuilder a = new StringBuilder();
a.AppendLine("line with no PII data.");
a.AppendLine("line with cvv: 123 data.");
a.AppendLine("line with cvc2: 123 data and some additional digits: 123.");
a.AppendLine("line with 23cvc2: 123 data with digits before and after.");
a.AppendLine("line with acvc: 123 data with the PII field surrounded by characters.");
a.AppendLine("line with cvca: 123 data with the PII field surrounded by characters.");
a.AppendLine("line with _cvc: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with -cvc: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with cvc_: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with cvc-: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with cvc-: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with __cvc: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with --cvc: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with cvc__: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with cvc--: 123 data with the PII field surrounded by special characters.");
a.AppendLine("line with cvc--: 123 data with the PII field surrounded by special characters.");
a.AppendLine("Some real life data next");
a.AppendLine(@" ""cardholder"": ""54**********0018"",");
a.AppendLine(@" ""nvr_entr_id"": ""54**********0041"",");
a.AppendLine(@" ""cvc_indnt_cd"": ""33"",");
a.AppendLine(@" ""cvc_indnt_2_cd"": ""333"",");
a.AppendLine(@" ""cvv_encd_cd"": ""333"",");
a.AppendLine(@" ""entr_pi_id"": ""54**********0041"",");
a.AppendLine(@" ""crd_exp_dt"": ""2706"",");
a.AppendLine(@" ""crd_srvs_pin"": ""201""");
a.AppendLine(@" <cardholder>54**********0018</cardholder>,");
a.AppendLine(@" <nvr_entr_id>54**********0041</nvr_entr_id>,");
a.AppendLine(@" <cvc_indnt_cd>33</cvc_indnt_cd>,");
a.AppendLine(@" <cvc_indnt_2_cd>333</cvc_indnt_2_cd>,");
a.AppendLine(@" <cvv_encd_cd>333</cvv_encd_cd>,");
a.AppendLine(@" <entr_pi_id>54**********0041</entr_pi_id>,");
a.AppendLine(@" <crd_exp_dt>2706</crd_exp_dt>,");
a.AppendLine(@" <crd_srvs_pin> 201 </crd_srvs_pin>");
string theText = a.ToString();
var lines = theText.Split(
new string[] { Environment.NewLine },
StringBuilder b = new StringBuilder();
if (Regex.IsMatch(x, @"(?<![^\W_\d])(cvv|cvc|expir|expr|exp|pin)(?![^\W_\d])"))
b.AppendLine(Regex.Replace(x, @"\d", "*"));
Console.WriteLine(b.ToString());