替换文本中的指定内容(电子邮件),以及其它指定的内容
2010-08-26 14:32
337 查看
<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)
{
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);
return stringToStrip;
}
<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)
{
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);
return stringToStrip;
}
相关文章推荐
- C# 查找文本内容(不区分大小写,空格)替换成指定的字符(查询分析器中查看存储过程内容时用)
- utf-8编码下替换指定文本内容源码
- 替换一个文本文件中的指定内容
- 如何使用JS脚本从HTML中分离图片标签与文本,替换文本中指定的内容并加粗(原创)
- 使用poi动态替换word指定文本内容
- shell 替换文本中的指定内容
- 关于文本输入框获取光标位置以及指定位置插入内容
- Sed替换文本中的指定内容
- 文本域文字内容指定选中实例页面(只选中文本中的一些字段)
- File文件基本操作之二:java 替换指定文件中的指定内容
- UltraEdit中将指定内容替换成回车换行
- [Java] 利用xpdf库获取pdf文件的指定范围文本内容
- sql replace 替换字段中部份指定内容
- 返回所选(当前)段落指定行号的文本内容一(VBA)
- Java读取文本指定的某一行内容
- 字符串的替换(直接替换你想要替换的字符串内容)/删除(删除指定位置/删除你要要删除的位置)/
- python 使用-读取文件、替换文件中指定的内容
- Java中读取txt文本中内容+目录文件复制到指定目录
- Mac 文本内容替换快捷键
- linux下批量查找/替换文本内容