gpt4 book ai didi

c# - 从 html 字符串匹配电子邮件正则表达式

转载 作者:行者123 更新时间:2023-12-02 04:41:20 25 4
gpt4 key购买 nike

通过 html 文本获取电子邮件有点麻烦

     string istr = "<a href = 'mailto:myemail@mail.com'>Email owner</a>";
protected void Button1_Click(object sender, EventArgs e)
{

// var emailregex = new Regex(@"\b\S+@mail\.com\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);

var emailregex = new Regex(@"\b(?<mail>[a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);

Label1.Text = emailregex.Replace(istr, "${mail}");
}

我没有收到“myemail@mail.com”。输出是完整的 html 字符串

有什么想法吗?

最佳答案

你可以使用匹配方法

emailregex.Match(istr).Groups["mail"].Value

关于c# - 从 html 字符串匹配电子邮件正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20782578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com