假设段落中的电子邮件地址现在是一个带有名称的字符串,如何替换它? 像[email protected] = xx , .com , .ae
输入=“联系[email protected]或[email protected]了解更多详情”
输出 =“联系 Abc 或 Defg 了解更多详细信息”
最佳答案
既然您需要正则表达式,我就给您一个。
Regex regex = new Regex(@"(\.|[a-z]|[A-Z]|[0-9])*@(\.|[a-z]|[A-Z]|[0-9])*");
foreach (Match match in regex.Matches(inputString))
{
// match.Value == "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="443c3c043d252c2b2b6a272b296a293d" rel="noreferrer noopener nofollow">[email protected]</a>"
string name = match.Groups[1]; // "xx"
string domain = match.Groups[2]; // "yahoo.com.my"
}
关于c# - 如何使用 C# 中的正则表达式将文本中的电子邮件地址替换为姓名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15611909/