急求 C#中的正则大侠们 快来帮忙??????????????????? 本帖最后由 swb1203 于 2010-07-13 19:15:21 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 (?is)comInformation.asp\?id=(?<id>\d+)[^>]*>(?<position>[^<>]+).+?companyJob.asp\?fzy=(?<company_id>\d+)[^>]*>(?<company>[^<>]+)分别:idpositioncompany_idcompany四个分组的值就是你要的 string test = @"<dl><!-- style=""color:#0066ff; text-decoration:none;""--> <dt><h3><a href=""http://www.shr.com/newcreate/comInformation.asp?id=70396"" target=""_blank"">Asp程序员 </a><!--软件工程师--></h3> | 工作地点:河南省郑州市| 工作经验:2年 | 学历:大专 | 发布时间:2010-7-12 </dt><dd><h4><a href=""http://www.shr.com/companyJob.asp?fzy=46501"" target=""_blank"">郑州XX实业有限公司</a> <img src='http://www.shr.com/newcreate/images/vip1.gif' width='31' height='13' /> <a href='http://www.baidu.com/baidu?word=%D6%A3%D6%DD%C9%CF%C9%C6%C8%F4%CB%AE%CA%B5%D2%B5%D3%D0%CF%DE%B9%AB%CB%BE' target='_blank'><font color='#FF0000'</dd>"; Match m = Regex.Match(test, @"(?is)comInformation.asp\?id=(?<id>\d+)[^>]*>(?<position>[^<>]+).+?companyJob.asp\?fzy=(?<company_id>\d+)[^>]*>(?<company>[^<>]+)"); if (m.Success) { Console.WriteLine("职员编号=" + m.Groups["id"].Value); Console.WriteLine("职位=" + m.Groups["position"].Value); Console.WriteLine("公司编号=" + m.Groups["company_id"].Value); Console.WriteLine("公司名=" + m.Groups["company"].Value); } position 的值并没有得到啊 怎么可能嘛。你测试没。你的职位这里有换行,所以到第二行显示了。我当时就怕你不会,但想想。不至于给了例子还要手把手的把细节都处理掉,因为例子就是例子,你最终的应用才需要处理细节。既然你不愿意思考,贴出来去掉回车换行的吧。诶。我不信你真的测试过,至少你没有debug的看每个匹配结果是什么。 private static void TestRegex08() { string test = @"<dl><!-- style=""color:#0066ff; text-decoration:none;""--> <dt><h3><a href=""http://www.shr.com/newcreate/comInformation.asp?id=70396"" target=""_blank"">Asp程序员 </a><!--软件工程师--></h3> | 工作地点:河南省郑州市| 工作经验:2年 | 学历:大专 | 发布时间:2010-7-12 </dt><dd><h4><a href=""http://www.shr.com/companyJob.asp?fzy=46501"" target=""_blank"">郑州XX实业有限公司</a> <img src='http://www.shr.com/newcreate/images/vip1.gif' width='31' height='13' /> <a href='http://www.baidu.com/baidu?word=%D6%A3%D6%DD%C9%CF%C9%C6%C8%F4%CB%AE%CA%B5%D2%B5%D3%D0%CF%DE%B9%AB%CB%BE' target='_blank'><font color='#FF0000'</dd>"; Match m = Regex.Match(test, @"(?is)comInformation.asp\?id=(?<id>\d+)[^>]*>(?<position>[^<>]+).+?companyJob.asp\?fzy=(?<company_id>\d+)[^>]*>(?<company>[^<>]+)"); if (m.Success) { Console.WriteLine("职员编号=" + m.Groups["id"].Value.Trim("\r\n".ToCharArray())); Console.WriteLine("职位=" + m.Groups["position"].Value.Trim("\r\n".ToCharArray())); Console.WriteLine("公司编号=" + m.Groups["company_id"].Value.Trim("\r\n".ToCharArray())); Console.WriteLine("公司名=" + m.Groups["company"].Value.Trim("\r\n".ToCharArray())); } } 字符串判断更快的方法,谢谢 InstallShield打包问题! 能不能用文本框实现QQ聊天窗口的功能? 一个关于字符串编码的问题,望高人指教一二 高手请进:关于asp.et页面大小的问题? 寻求一个正则表达式,请大家帮忙啦。 第一个帖子没解决,在发个帖子,如果会的朋友,接第一个帖子,2个都给分 如何在文本方式中引用 system.management.dll? C# webBrowser和messagebox的问题 谢谢GG了,如何冻结DataGridView的行? 在服务器端向页面表中插入一行 ClickOnce安装问题!!!!!!!!!
id
position
company_id
company
四个分组的值就是你要的
<!-- style=""color:#0066ff; text-decoration:none;""--> <dt><h3><a href=""http://www.shr.com/newcreate/comInformation.asp?id=70396"" target=""_blank"">
Asp程序员 </a><!--软件工程师--></h3>
| 工作地点:河南省郑州市| 工作经验:
2年 | 学历:大专
| 发布时间:2010-7-12 </dt>
<dd><h4><a href=""http://www.shr.com/companyJob.asp?fzy=46501"" target=""_blank"">郑州XX实业有限公司</a> <img src='http://www.shr.com/newcreate/images/vip1.gif' width='31' height='13' /> <a href='http://www.baidu.com/baidu?word=%D6%A3%D6%DD%C9%CF%C9%C6%C8%F4%CB%AE%CA%B5%D2%B5%D3%D0%CF%DE%B9%AB%CB%BE' target='_blank'><font color='#FF0000'</dd>
";
Match m = Regex.Match(test, @"(?is)comInformation.asp\?id=(?<id>\d+)[^>]*>(?<position>[^<>]+).+?companyJob.asp\?fzy=(?<company_id>\d+)[^>]*>(?<company>[^<>]+)");
if (m.Success)
{
Console.WriteLine("职员编号=" + m.Groups["id"].Value);
Console.WriteLine("职位=" + m.Groups["position"].Value);
Console.WriteLine("公司编号=" + m.Groups["company_id"].Value);
Console.WriteLine("公司名=" + m.Groups["company"].Value);
}
你的职位这里有换行,所以到第二行显示了。
我当时就怕你不会,但想想。不至于给了例子还要手把手的把细节都处理掉,因为例子就是例子,你最终的应用才需要处理细节。既然你不愿意思考,贴出来去掉回车换行的吧。诶。我不信你真的测试过,至少你没有debug的看每个匹配结果是什么。 private static void TestRegex08()
{
string test = @"<dl>
<!-- style=""color:#0066ff; text-decoration:none;""--> <dt><h3><a href=""http://www.shr.com/newcreate/comInformation.asp?id=70396"" target=""_blank"">
Asp程序员 </a><!--软件工程师--></h3>
| 工作地点:河南省郑州市| 工作经验:
2年 | 学历:大专
| 发布时间:2010-7-12 </dt>
<dd><h4><a href=""http://www.shr.com/companyJob.asp?fzy=46501"" target=""_blank"">郑州XX实业有限公司</a> <img src='http://www.shr.com/newcreate/images/vip1.gif' width='31' height='13' /> <a href='http://www.baidu.com/baidu?word=%D6%A3%D6%DD%C9%CF%C9%C6%C8%F4%CB%AE%CA%B5%D2%B5%D3%D0%CF%DE%B9%AB%CB%BE' target='_blank'><font color='#FF0000'</dd>
";
Match m = Regex.Match(test, @"(?is)comInformation.asp\?id=(?<id>\d+)[^>]*>(?<position>[^<>]+).+?companyJob.asp\?fzy=(?<company_id>\d+)[^>]*>(?<company>[^<>]+)");
if (m.Success)
{
Console.WriteLine("职员编号=" + m.Groups["id"].Value.Trim("\r\n".ToCharArray()));
Console.WriteLine("职位=" + m.Groups["position"].Value.Trim("\r\n".ToCharArray()));
Console.WriteLine("公司编号=" + m.Groups["company_id"].Value.Trim("\r\n".ToCharArray()));
Console.WriteLine("公司名=" + m.Groups["company"].Value.Trim("\r\n".ToCharArray()));
}
}