日期:2014-05-18  浏览次数:20437 次

求正则的写法
想从<a onmouseup="1231" href="www.a.com" target="_self">张三</a>中匹配出www.a.com和张三

Regex re = new Regex(@"(?<=<a\s*onmouseup=""[^""]+""\s*href="")[^""]+(?="")", RegexOptions.None);
MatchCollection mc = re.Matches(sourcecode);
string tar="";
foreach (Match ma in mc)
{
  tar+=ma.Value
}
上面可以匹配www.a.com,但怎么匹配出张三呢?




------解决方案--------------------
探讨
想从<a onmouseup="1231" href="www.a.com" target="_self">张三</a>中匹配出www.a.com和张三

Regex re = new Regex(@"(?<=<a\s*onmouseup=""[^""]+""\s*href="")[^""]+(?="")", RegexOptions.None);
MatchCollection mc = ……

------解决方案--------------------
探讨

引用:
正则没调好

C# code


Regex re = new Regex(@"<a\s*onmouseup=""([^""]*)""\s*href=['""]([^'""\s>]+)[^>]*>([\s\S]+?)</a>", RegexOptions.None);
MatchCollection mc = re.Matches(s……