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

正则提取--新手问题
get网址,返回数据
C# code
<a href="http://as.xxx.com/" onclick="co('as')">鞍山</a><a href="http://ay.xxx.com/" onclick="co('ay')">安阳
...
...
</a>


里面有大量类似上述的代码,
特征码
co('as')
co('ay')
如何提取得到代码中类似
as
ay
..


------解决方案--------------------
C# code
        string s=@"<a href=""http://as.xxx.com/"" onclick=""co('as')"">鞍山</a><a href=""http://ay.xxx.com/"" onclick=""co('ay')"">安阳
...
...
</a>";
        MatchCollection matches = Regex.Matches(s, @"(?is)(?<=onclick=""co\(')[^']+(?='\))");
        foreach (Match match in matches)
            Response.Write(match.Value + "<br/>");

------解决方案--------------------
(?<=co\(')[^']+(?='\))