Quantifier range not working in lookbehind

杀马特。学长 韩版系。学妹 提交于 2019-12-05 10:45:29

PHP, like many flavors, doesn't support variable length lookbehind. The only support is alternation (|) at the top level of the lookbehind. Even a ? can break the pattern. An alternative is to use:

(?<=\*[ \t]|\*[ \t]{2}|\*[ \t]{3}|\*[ \t]{4}).*

Or better, abort the lookbehind for a group:

\*[ \t]{1,4}(.*)

This should work well for you, since it doesn't seem like you have overlapping of your matches anyway.

From the manual:

The contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixed length. However, if there are several alternatives, they do not all have to have the same fixed length. Thus (?<=bullock|donkey) is permitted, but (?<!dogs?|cats?) causes an error at compile time. Branches that match different length strings are permitted only at the top level of a lookbehind assertion.

Source: http://www.php.net/manual/en/regexp.reference.assertions.php

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