【发布时间】:2011-12-19 16:36:35
【问题描述】:
在文本中,我想找到像每件事一样的结构,直到某些文本,但在某些单词之间不匹配。
文本示例:
Templates : You can add custom templates for your theme. Updated on 2010 look[124] end
Media RSS feed : Add the Cooliris Effect to your gallery Updated on 2011 look[124]
Role settings : Each gallery has a author Updated at 2010 ... look[124] end
AJAX based thumbnail generator : No more server Updated on 2010 look[124] end limitation during the batch process Copy/Move : Copy or move images between Updated on 2010 this look[124] galleries Sortable Albums : Create your own sets of images Updated on 2010 this look[124] end
Upload or pictures via a zip-file (Not in Safe-mode)
Watermark function : You can add a watermark image or text
...
我需要找到 "Updated .*[124] end" 每场比赛都必须开始这个 "Update" 并以 "[number]" 和单词 "end 结尾”。但有些文本看起来非常相似,但 not 以单词“end”结尾。此文本必须不匹配。如何让它发挥作用?
我试着写
/Updated(.*?)\[.*?\]\send/msi
或
Updated(.*?)\[.*?\](?!Updated)\send
但这需要像这样的字符串:
Updated on 2011 look[124] Role settings : Each gallery has a author Updated at 2010 ... look[124] end
Updated on 2010 this look[124] galleries Sortable Albums : Create your own sets of images Updated on 2010 this look[124] end
如何编写正则表达式女巫跳过糟糕的匹配?
感谢您的意见。
【问题讨论】:
-
而且,请记住,正则表达式是贪婪的,它们会尝试匹配一行中最长的东西
标签: php regex preg-match