C#替换部分消息

时间:2016-01-21 05:52:24

标签: c# regex

string message = "Your purchase of $ 100.00 is awaiting for confirmation. Please use PIN 8967 to complete the transaction. Reference Number :1237689";

string output = Regex.Replace(message, @"[\d-]", "*");

Console.WriteLine("Message : " + message);

Console.WriteLine("Output : " + output);

Console.ReadLine();

我想只替换邮件的PIN。但是上面的消息会替换*字符中的所有数值。

1 个答案:

答案 0 :(得分:3)

mysql --user=root --password=`cat /root/.mysql`

string message = "Your purchase of $ 100.00 is awaiting for confirmation. Please use PIN 8967 to complete the transaction. Reference Number :1237689";
string output = Regex.Replace(message, @"(?<=PIN\s*\d*)\d", "*");