Bra*_*tie 10
与其他回复类似,也有所不同.也接受.co.uk地址.
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
String regex = @"(.{2}).+@.+(.{2}(?:\..{2,3}){1,2})";
String replace = "$1*@*$2";
List<String> tests = new List<String>(new String[]{
"joe@example.com",
"jim@bob.com",
"susie.snowflake@heretoday.co.uk",
"j@b.us",
"bc@nh.us"
});
tests.ForEach(email =>
{
Console.WriteLine(Regex.Replace(email, regex, replace));
});
}
}
Run Code Online (Sandbox Code Playgroud)
结果是:
jo*@*le.com
ji*@*ob.com
su*@*co.uk
j@b.us
bc@nh.us
Run Code Online (Sandbox Code Playgroud)
虽然我不是百分之百确定你想要用两边只有2个字母的名字做什么(因此最后两个结果).但这是我的出价.例