读书人

正则提取-新手有关问题

发布时间: 2012-02-27 10:00:22 作者: rapoo

正则提取--新手问题
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\(')[^']+(?='\))

读书人网 >C#

热点推荐