preg_match appears to hit a limit when using two matches

前端 未结 2 1548
醉梦人生
醉梦人生 2021-01-19 00:12

I have run up against an odd problem. it appears i am reaching some sort of limit with preg_replace while trying to use two matches using php-5.3.3

// works         


        
2条回答
  •  灰色年华
    2021-01-19 00:46

    About PHP not being talkative about its errors, you can use T-Regx library, which always throws an exception:

    // didnt work
    $pattern_2 = '/START-ONE(.*)STOP-ONE.*START-TWO(.*)STOP-TWO.*/';
    $string = 'START-ONE this is head stuff STOP-ONE  START-TWO' . str_repeat('x', 959971) . 'STOP-TWO';
    
    try {
        pattern($pattern_2)->match($string)->first();
    }
    catch ($e) {
        $m = $e->getMessage();
        $m // After invoking preg_match(), preg_last_error() returned PREG_BACKTRACK_LIMIT_ERROR.
    }
    

提交回复
热议问题