<div>
<asp:TextBox ID="TextBox1" runat="server" Width="519px"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" Width="65px"
onclick="Button1_Click" /><br />
<asp:TextBox ID="TextBox2" runat="server" Width="520px"></asp:TextBox>
</div>
protected void Button1_Click(object sender, EventArgs e)
{
Regex regex = new Regex(@"([/w-]+(/./w+)*@([/w-]+/.)+/w{2,3})", RegexOptions.IgnoreCase); 正则根据自己的需求进行更改。
string str= regex.Replace(TextBox1 .Text, ""); 将textBox1文本框中的电子邮件替换为"",替换内容可自定义
Match match = regex.Match(TextBox1.Text); //匹配文本框的中电子邮件
TextBox2.Text = match .Groups [0].Value ; //取出文本框中的电子邮件
}
MatchCollection match = regex.Matches(str); //匹配多条
for (int i = 0; i < match.Count; i++)
{
//循环读取match内容
}
//去除HTML标记 public static string StripAllTags(string stringToStrip) return stringToStrip;
{
stringToStrip = Regex.Replace(stringToStrip, "</p(?://s*)>(?://s*)<p(?://s*)>", "/n/n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
stringToStrip = Regex.Replace(stringToStrip, "<br(?://s*)/>", "/n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
stringToStrip = Regex.Replace(stringToStrip, "/"", "''", RegexOptions.IgnoreCase | RegexOptions.Compiled);
stringToStrip = Regex.Replace(stringToStrip, "<[^>]+>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);
stringToStrip = Regex.Replace(stringToStrip, "&[^;]+;", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);
}