简体   繁体   中英

PHP preg_match - Maximum number of non-greedy matches

Is there a known limit of how many times I am allowed to use the non-greedy .*? match in a regular expression in PHP?

My haystack is ~ 200k characters and I have to find out, whether 75 Numbers are in the correct order. I know there are better ways to do this without using preg_match, but for the sake of this question, stay with me.

  • My first regular expression looked like @123.*?456.*?789.*?101112@ etc. with 75 numbers - it failed.

  • Second approach: Split after the first 30 numbers, so we have two regular expressions like the one above, the first one having 30 and the second one 45 numbers. The second one failed.

  • Third approach: Split after the first 40 numbers (So there are 40 and 35 numbers). Both succeeded.

I've made sure that number 39 and 40 are in order, so my guess is, that there are some limitations to preg_match.

通过增加此值进行检查

ini_set("pcre.backtrack_limit", "1000000");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM