首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

正则表达 去掉A标记 进来拿分。解决办法

2012-02-03 
正则表达去掉A标记 进来拿分。。。。。。。。ahref asff.htm target _blank 文字 /a 文字 Ahref a

正则表达 去掉A标记 进来拿分。。。。。。。。
<a   href= "asff.htm "   target= "_blank "> 文字 </a> <> 文字 <A   href= "asdf.htm "> 文字 </A>

我的要求是只剩下上面之中的字(不能删除全部html)     就是把这其中的   <a   > 标记删除掉

[解决办法]
public static string GetLinkUrl(string HTMLStr)
{
string str = string.Empty;

Regex r = new Regex(@ " <a\s+[^> ]*\s*href\s*=\s*([ ']?)(? <url> \S+) '?[^> ]*> ",
RegexOptions.Compiled);
Match m = r.Match(HTMLStr.ToLower());
if (m.Success)
str = m.Result( "${url} ");
return str;
}
[解决办法]
try

string yourStr = ...........;
string resultStr = Regex.Replace(yourStr, @ " </?a[^> ]*?> ", " ", RegexOptions.IgnoreCase);

热点排行
Bad Request.