读书人

正则表达式

发布时间: 2012-01-28 22:06:14 作者: rapoo

求助:正则表达式
help: 已知如下字串,我要提取[管理部][邮件][李龙][经理][电话]等信息出来,已知关键字只有mailto:可用(即必须判断mailto前面的是部门,紧接着是邮件,再后是姓名等),我该如何来写这个正则表达式呢??

注:不好意思,只有20分,大伙多帮帮忙!!


<tr>
<td class= "content4 " align= "center "> <font size=2> 8 </font> </td>
<td class= "content4 "> <font size=2> 管理部 </a> </font> </td>
<td align= "center "> <a href= "mailto:lixg@intranet " class= "a02 "> <font size=2> 李龙 </font> </a> </td>
<td class= "content4 "> <font size=2> 经理 </font> </td>
<td class= "content4 " align= "center "> <font size=2> 13608835710 </a> </font> </td>
<td class= "content4 " align= "center "> <font size=2> 5022 </font> </td>
<td class= "content4 " align= "center "> <a href= "/resume/show_resume.php?employee_id_temp1=1167 " class= "a02 "> <font size=2> 自我介绍 </font> </a> </td>
</tr>

[解决办法]
能不能再贴点代码出来。。
[解决办法]
哦,你还要序号啊。再加点


string matchtext=@ " <tr> \s* <td[^> ]+> \s* <font[^> ]+> (? <id> [^ <]+) </font> \s* </td> \s* <td[^> ]+> \s* <font[^> ]+> (? <manage> [^ <]+)( </a> )* </font> \s* </td> \s* <td[^> ]+> \s* <a\s+href=\ " "(? <mail> [^\ " "]+)\ " "[^> ]+> \s* <font[^> ]+> (? <name> [^ <]+) </font> </a> </td> \s* <td[^> ]+> <font[^> ]+> (? <job> [^ <]+) </font> </td> \s* <td[^> ]+> <font[^> ]+> (? <tel> \d+) </a> </font> </td> \s* <td[^> ]+> <font[^> ]+> (? <number> \d+) </font> </td> \s* <td[^> ]+> <a\s+href=\ " "(? <introduce> [^\ " "]+)\ " "[^> ]+> ";


MatchCollection mc=Regex.Matches(str,matchtext,RegexOptions.IgnoreCase);
foreach(Match match in mc)
{
id=match.Groups[ "id "].Value;
manage=match.Groups[ "manage "].Value;
mail=match.Groups[ "mail "].Value;
name=match.Groups[ "name "].Value;
job=match.Groups[ "job "].Value;
tel=match.Groups[ "tel "].Value;
number=match.Groups[ "number "].Value;
introduce=match.Groups[ "introduce "].Value;
}

剩下的自己搞咯。。。最好写个员工类,

读书人网 >asp.net

热点推荐