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

正则高手来帮下忙,正则表达试的问题
请教两个问题
1:
在这个网页中http://www.elong.com/hotels/details.aspx?m=commentary&hotelid=40101002
我想用正则表达式匹配出用户名,服务分,价格分,设施分
还有评论内容,正则表达式该怎么写??

2:在这个网页中:http://www.elong.com/hotels/
随便查找一个酒店,比如北京昆仑饭店,进入后,通过源代码会发现 北京昆仑饭店的ID是40101002 
我怎么把这个ID匹配出来??


高手帮忙解答下,谢谢各位

------解决方案--------------------
北京昆仑饭店的ID是40101002 
可以根据hotelid=40101002 得到
------解决方案--------------------
1、
C# code
<div\sclass="div_z1">[\s\S]+?<A[^>]+>(?<user>.+?)</A></div>[\s\S]+?<div\sclass="comment_pftext">(?<service>.+?)</div>[\s\S]+?<div\sclass="comment_text"><b>(?<content>[\s\S]+?)<span[\s\S]+?>

------解决方案--------------------
第一个问题

C# code
MatchCollection mc = Regex.Matches(str, @"用户:(\s*<[^>]*>)*(?<user>[^<>]*)[\s\S]*?服务:\s*(?<service>\d+)[\s\S]*?价格:\s*(?<price>\d+)[\s\S]*?设施:\s*(?<est>\d+)", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
    richTextBox1.Text += m.Groups["user"].Value + "\n";
    richTextBox1.Text += m.Groups["service"].Value + "\n";
    richTextBox1.Text += m.Groups["price"].Value + "\n";
    richTextBox1.Text += m.Groups["est"].Value + "\n";
}