Home > Backend Development > PHP Tutorial > 哎,求2个正则合并成一个正则怎么写啊,谢谢

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:09:44
Original
1030 people have browsed it

这是要匹配的内容

<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>
Copy after login


这个个正则,怎么合并成一个啊
$a = preg_match_all('/LightRowHead.*?>(.*?):.*?LightRow.*?>(.*?)</is', $content, $a);$a = preg_match_all('/DarkRowHead.*?>(.*?):.*?DarkRow.*?>(.*?)</is', $content, $b);
Copy after login

我这样写不对
$a = preg_match_all('/[LightRowHead|DarkRowHead].*?>(.*?):.*?[LightRow|DarkRow].*?>(.*?)</is', $content, $c);
Copy after login


求高人指点


回复讨论(解决方案)

(xx|yy)

用方括号括起就变成字符单选了,要用圆括号
$a = preg_match_all('/(LightRowHead|DarkRowHead).*?>(.*?):.*?(LightRow|DarkRow).*?>(.*?)', $content, $LightRowHead);
不想加入向前引用的话可写作
$a = preg_match_all('/(?:LightRowHead|DarkRowHead).*?>(.*?):.*?(?:LightRow|DarkRow).*?>(.*?)', $content, $LightRowHead);

需要前后配对的话可写作
$a = preg_match_all('/(LightRow|DarkRow)Head.*?>(.*?):.*?\\1.*?>(.*?)', $content, $LightRowHead);

用方括号括起就变成字符单选了,要用圆括号
$a = preg_match_all('/(LightRowHead|DarkRowHead).*?>(.*?):.*?(LightRow|DarkRow).*?>(.*?)', $content, $LightRowHead);
不想加入向前引用的话可写作
$a = preg_match_all('/(?:LightRowHead|DarkRowHead).*?>(.*?):.*?(?:LightRow|DarkRow).*?>(.*?)', $content, $LightRowHead);

需要前后配对的话可写作
$a = preg_match_all('/(LightRow|DarkRow)Head.*?>(.*?):.*?\\1.*?>(.*?)', $content, $LightRowHead);
果然,csdn的人就是热情,谢谢你和二楼..

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template