请参考下列代码
//例如我要把邮箱前面的shelher全部替换为**
var email = "shelher@qq.com";
Console.WriteLine(Regex.Replace(email, @"^(\w+)@(\w+\.\w+)$", Repl));
Console.ReadKey();
static string Repl(Match match)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < match.Groups[1].Length; i++)
{
sb.Append("*");
}
return sb.Append(match.Groups[2]).ToString();
}
如有疑问请追问