php regex: lookbehind and lookahead and greediness problem

好久不见. 提交于 2019-12-01 05:29:31

This should do it:

(?<=\[p2\]).+?(?=\[\/p2\])

I added the question mark to make the quantifier non-greedy.

Instead of using a regex modifier, you can use the standard perl style match modifier and add a ? after + or * to tell that specific portion to be non-greedy. Mentioned above, but specificity can help.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!