匹配出下面有用的信息的正则怎么写?
<div class= "basic "> <P> 男| 1980年10月|户口所在地:中国 广东省深圳|团员 </P> <P> 上海 </P> <P> 13585803497(手机)|021-64855058-7823(工作电话) </P> <P> E-mail: <A HREF= "mailto:vallen_wang@163.com "> vallen_wang@163.com </A> </P> </div> </div> <h2> 汪斌 <span class= "en "> (Vallen Wang) </span> <span class= "bas "> (男,26岁) </span> </h2>
匹配出性别,出生年月,电话,姓名?
[解决办法]
格式固定吗?可也够乱的
string yourStr = " <div class=\ "basic\ "> <P> 男| 1980年10月|户口所在地:中国 广东省深圳|团员 </P> <P> 上海 </P> <P> 13585803497(手机)|021-64855058-7823(工作电话) </P> <P> E-mail: <A HREF=\ "mailto:vallen_wang@163.com\ "> vallen_wang@163.com </A> </P> </div> </div> <h2> 汪斌 <span class=\ "en\ "> (Vallen Wang) </span> <span class=\ "bas\ "> (男,26岁) </span> </h2> ";
Match m = Regex.Match(yourStr, @ " <div\s+class= " "basic " "> \s* <P> \s*(? <sex> [^|]*)\|\s*(? <birthday> [^|]*)\|[\s\S]*? </P> <P> [\s\S]*? </P> <P> (? <phone> [\s\S]*?) </P> [\s\S]*? <h2> (? <name> [^ <]*) < ", RegexOptions.IgnoreCase);
if (m.Success)
{
Response.Write(m.Groups[ "sex "].Value + " <br> ");
Response.Write(m.Groups[ "birthday "].Value + " <br> ");
Response.Write(m.Groups[ "phone "].Value + " <br> ");
Response.Write(m.Groups[ "name "].Value + " <br> ");
}