哎,求2个正则合并成一个正则怎么写啊,谢谢

cluonani 2013-05-13 02:39:27
这是要匹配的内容

<td class="LightRowHead">
Primary Color:
</td>
<td class="LightRow">
Multi-Color
</td>
</tr>
<tr>
<td class="DarkRowHead">
Multi Pack Indicator:
</td>
<td class="DarkRow">
No
</td>
</tr>
<tr>
<td class="LightRowHead">
Battery Type:
</td>
<td class="LightRow">
Does Not Contain a Battery
</td>
</tr>


这个个正则,怎么合并成一个啊

$a = preg_match_all('/LightRowHead.*?>(.*?):.*?LightRow.*?>(.*?)</is', $content, $a);
$a = preg_match_all('/DarkRowHead.*?>(.*?):.*?DarkRow.*?>(.*?)</is', $content, $b);

我这样写不对

$a = preg_match_all('/[LightRowHead|DarkRowHead].*?>(.*?):.*?[LightRow|DarkRow].*?>(.*?)</is', $content, $c);


求高人指点
...全文
125 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cluonani 2013-05-13
  • 打赏
  • 举报
回复
引用 2 楼 xuzuning 的回复:
用方括号括起就变成字符单选了,要用圆括号 $a = preg_match_all('/(LightRowHead|DarkRowHead).*?>(.*?):.*?(LightRow|DarkRow).*?>(.*?)</is', $content, $LightRowHead); 不想加入向前引用的话可写作 $a = preg_match_all('/(?:LightRowHead|DarkRowHead).*?>(.*?):.*?(?:LightRow|DarkRow).*?>(.*?)</is', $content, $LightRowHead); 需要前后配对的话可写作 $a = preg_match_all('/(LightRow|DarkRow)Head.*?>(.*?):.*?\\1.*?>(.*?)</is', $content, $LightRowHead);
果然,csdn的人就是热情,谢谢你和二楼..
xuzuning 2013-05-13
  • 打赏
  • 举报
回复
用方括号括起就变成字符单选了,要用圆括号 $a = preg_match_all('/(LightRowHead|DarkRowHead).*?>(.*?):.*?(LightRow|DarkRow).*?>(.*?)</is', $content, $LightRowHead); 不想加入向前引用的话可写作 $a = preg_match_all('/(?:LightRowHead|DarkRowHead).*?>(.*?):.*?(?:LightRow|DarkRow).*?>(.*?)</is', $content, $LightRowHead); 需要前后配对的话可写作 $a = preg_match_all('/(LightRow|DarkRow)Head.*?>(.*?):.*?\\1.*?>(.*?)</is', $content, $LightRowHead);
床上等您 2013-05-13
  • 打赏
  • 举报
回复
(xx|yy)

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧