正则表达式匹配a标签的href

JS代码:

<html>
<head>
<script language="javascript"> 
    var a='<P><A href=\'~abc/ccg/ab.jpg\' width="3">文字</A><A width="4" style="color:#ddd; font-weight:bold;" mm_href="http:www.baidu.com"  href="http://bbs.cn.yimg.com/user_img/200701/31/soso1.jpg" mce_href="http://bbs.cn.yimg.com/user_img/200701/31/jisuanji986_117025184198149.jpg">cc</A> href="www.baidu.com" cbas <span>cchref</span> 1<a dd href="ccc"  <A width="5" href="http://bbs.cn.yimg.com/user_img/200701/31/soso2.jpg" mce_href="http://bbs.cn.yimg.com/user_img/200701/31/cc.jpg"></A></P>';
    
    var b=/<a([\s]+|[\s]+[^<>]+[\s]+)href=(\"([^<>"\']*)\"|\'([^<>"\']*)\')[^<>]*>/gi;
    var s=a.toLowerCase().match(b);
    alert(s.length);
    for(var i= 0;i<s.length;i++) 
    { 
        var ss = s[i].toLowerCase().match(b);
        alert(RegExp.$3+RegExp.$4);
    } 
</script>
</head>
<body>
</body>
</html>

C#代码:

string html = "<P><A href='~abc/ccg/ab.jpg' height=\"4\" width='3' >文字</A><A width=\"4\" style=\"color:#ddd; font-weight:bold;\" mm_href=\"http:www.baidu.com\"  href=\"http://bbs.cn.yimg.com/user_img/200701/31/soso1.jpg\" mce_href=\"http://bbs.cn.yimg.com/user_img/200701/31/jisuanji986_117025184198149.jpg\">cc</A> href=\"www.baidu.com\" cbas <span>cchref</span>  1<a df href=\"cc\"   <A width=\"5\" href=\"http://bbs.cn.yimg.com/user_img/200701/31/soso2.jpg\" mce_href=\"http://bbs.cn.yimg.com/user_img/200701/31/cc.jpg\"></A></P>";

Regex reg = new Regex("<a([\\s]+|[\\s]+[^<>]+[\\s]+)href=(\"(?<href>[^<>\"']*)\"|'(?<href>[^<>\"']*)')[^<>]*>",RegexOptions.IgnoreCase);
MatchCollection matchCollection = reg.Matches(html);
MessageBox.Show(matchCollection.Count.ToString());
foreach (Match match in matchCollection)
{
    MessageBox.Show(match.Groups["href"].ToString());
}

相关文章

jquery.validate使用攻略(表单校验) 目录 jquery.validate...
/\s+/g和/\s/g的区别 正则表达式/\s+/g...
自整理几个jquery.Validate验证正则: 1. 只能输入数字和字母...
this.optional(element)的用法 this.optional(element)是jqu...
jQuery.validate 表单动态验证 实际上jQuery.validate提供了...
自定义验证之这能输入数字(包括小数 负数 ) &lt;script ...