Press "Enter" to skip to content

A Deep Dive into PCRE's Max Backtrack/Recursion Limits

Today, Tank asked about this regex:

/<script>.*?</script>/is

When the string to be matched is longer than 100014, it will not produce the correct result:

$reg = "/<script>.*?</script>/is";
$str = "<script>********</script>"; //length greater than 100014
$ret = preg_replace($reg, "", $str); //returns NULL

Does a regex impose a length limit on the string it matches?

Filed in English, PHP应用, PHP源码分析
with 0 Comment