在正则表达式模式中包含 OR (PHP)
尝试创建包含或条件的模式。
$pattern["body"]='/(<\/a><\/li><\/ul><\/div><p>|<h2>)(.*)<div class="like">/s';
该模式应识别一系列“ ”之间的任何文本 或“<\/a><\/li><\/ul><\/div>
”作为开始分隔符,但显然 or 条件在这种情况下不起作用。 任何人都可以提供正确语法的提示!?我努力了1个小时,我已经失去了对这条规则的专注和耐心。 先感谢您。
Trying to create a pattern that includes an or condition.
$pattern["body"]='/(<\/a><\/li><\/ul><\/div><p>|<h2>)(.*)<div class="like">/s';
The pattern should recognize any text between a series of "<\/a><\/li><\/ul><\/div><p>
" or a "<h2>
" as the beginning delimiter, but apparently the or condition does not work in this case.
Anyone can offer a hint for the correct syntax!? I am striving for 1 hour and I have lost the focus and patience in this rule.
THank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅下面的 grep 测试:
see below grep test:
我没有任何样本数据可供测试,但看起来您就在那里。我只是改变了分隔符,这样就不必转义了,我发现它更容易理解。
I don't have any sample data to test against but it looks like you were there. I only changed the delimiter so it wouldn't have to be escaped, I find it's easier to understand.
这可能有效 http://www.ideone.com/zYB1n
但是,我不是 php 专家。
This might work http://www.ideone.com/zYB1n
But, I'm no php expert.