求一个正则表达式,去掉<a>标记 这里有一个字符串 “请访问如下链接<a hrdf='http://www.sohu.com'>sohu</a>”我想把<a hrdf='http://www.sohu.com'> </a> 去掉。 只剩下“请访问如下链接 sohu”知道的指教下,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Regex re = new Regex(@"<a\s+(?:(?!</a>).)*?>|</a>", RegexOptions.None);string result = re.Replace(@"请访问如下链接 <a hrdf='http://www.sohu.com'>sohu </a>","");Console.WriteLine(result);/*请访问如下链接 sohu */ using System.Text.RegularExpressions; //已测试过 string strContent = "<a hrdf='http://www.sohu.com'>sohu </a>"; Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled); strContent = urlregex.Replace(strContent, "$1"); Response.Write(strContent); 非常感谢我还想问楼上一个问题,我用C#代码写的,用string.replace < 和 > 之间的,用递归实现的。因为一个输入字符串里可能有多个 链接请问 我的写法和 用正则来比 效率有多大的区别呢??谢谢 static void Main(string[] args) { Regex r = new Regex(@"<a[^>]*>|</a>$"); string result = r.Replace(@"请访问如下链接 <a hrdf='http://www.sohu.com'>sohu </a>", ""); Console.WriteLine(result); } override关键字 【菜鸟提问】关于浏览器兼容的问题 求助:mapxtreme 2008,鹰眼,两个以上的地图控件 dataGrid和aspnetpager无法分页 有关DropDownList的问题! scriptmanager无法同时处理多个请求 关于其他类调用的问题,高手帮忙 如何引用类?? Microsoft VBScript 运行时错误 '800a01a8' 缺少对象: '' 初学做了个带SQL数据表的录入、查询小网站,想要求使用特定帐号、密码登录此网站,却不知如何下手? 后台代码自制js与火狐兼容的问题 关于ajax的timer控件求教!!
string result = re.Replace(@"请访问如下链接 <a hrdf='http://www.sohu.com'>sohu </a>","");
Console.WriteLine(result);
/*
请访问如下链接 sohu
*/
string strContent = "<a hrdf='http://www.sohu.com'>sohu </a>";
Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
strContent = urlregex.Replace(strContent, "$1");
Response.Write(strContent);
谢谢
{
Regex r = new Regex(@"<a[^>]*>|</a>$");
string result = r.Replace(@"请访问如下链接 <a hrdf='http://www.sohu.com'>sohu </a>", "");
Console.WriteLine(result); }