110,499
社区成员
发帖
与我相关
我的任务
分享
public string Trans(string input)
{
//string input = "hh@133.com;范幼敏,吴国民,王翔;ee@134.com;;;fanyoumin@gc.com;";
string output = string.Empty;
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})");
System.Text.RegularExpressions.MatchCollection mc = regex.Matches(input);
foreach (System.Text.RegularExpressions.Match m in mc)
{
output += m.Value + ";";
}
return output;
}
void Main()
{
string str="hh@133.com;范幼敏,吴国民,王翔;ee@134.com;;;fanyoumin@gc.com;";
str=Regex.Replace(str,@"(?:[\u4e00-\u9fa5]+[,;]|;{2,})",m=>Regex.IsMatch(m.Value,";{2,}")?";":"");
Console.WriteLine(str);//hh@133.com;ee@134.com;fanyoumin@gc.com;
}