文件内容:
<DIV id=tab_Result>\r\n<TABLE style=TABLE-LAYOUT: fixed; WORD-WRAP: break-word cellSpacing=0 cellPadding=5 width=530 border=0>\r\n<TBODY>\r\n<TR>\r\n<TD align=middle width=171 rowSpan=3><A class=unl href=http://lac.xx.com/cgi-bin/userinfo?userid=06085888 target=_blank><IMG height=111 src=http://loveimg2Regex regUserID = new Regex(@"><A class=unl href=http://lac.xx.com/cgi-bin/userinfo?userid=([^<]*)<",RegexOptions.IgnoreCase|RegexOptions.Multiline|RegexOptions.Compiled);MatchCollection mcUserID = regUserID.Matches(xmlStr);mcUserID.Count怎么是0呢?我要得到06085888(userid=后面的内容)怎么写正则表达式?
<DIV id=tab_Result>\r\n<TABLE style=TABLE-LAYOUT: fixed; WORD-WRAP: break-word cellSpacing=0 cellPadding=5 width=530 border=0>\r\n<TBODY>\r\n<TR>\r\n<TD align=middle width=171 rowSpan=3><A class=unl href=http://lac.xx.com/cgi-bin/userinfo?userid=06085888 target=_blank><IMG height=111 src=http://loveimg2Regex regUserID = new Regex(@"><A class=unl href=http://lac.xx.com/cgi-bin/userinfo?userid=([^<]*)<",RegexOptions.IgnoreCase|RegexOptions.Multiline|RegexOptions.Compiled);MatchCollection mcUserID = regUserID.Matches(xmlStr);mcUserID.Count怎么是0呢?我要得到06085888(userid=后面的内容)怎么写正则表达式?
为什么要那么复杂
string regexStr = @"userid=(\d+)";
MatchCollection mc = Regex.Matches(yourStr, regexStr);
foreach(Match m in mc)
{
m.Groups[1].Value;//06085888
}
MatchCollection mc = Regex.Matches(yourStr, regexStr);这样的话 mc.Count也是0 ,为什么?(userinfo?userid= 这里的?有问题吗?)
string regexStr = "userinfo\\?userid";
或者
string regexStr = @"userinfo\?userid";