1

I'm having the weirdest issue. I've tried referencing other similar answers here, but none seem to fix my issue.

I have the following regex in PHP

/if\s+(?:(.*?)\s*==\s*(?:UrlStatus|DeadURL)|in_array\s*\((?:UrlStatus|DeadURL),\s*(.*?)\s*\))\s*then\s+local\s+arch_text\s+=\s+cfg.messages\['archived'\];(?:(?:\n|.)*?if\s+(?:(.*?)\s*==\s*(?:UrlStatus|DeadURL)|in_array\s*\((?:UrlStatus|DeadURL),\s*(.*?)\s*\))\s*then\s+Archived = sepc \.\.)?/im

It's a messy regex I know, it's supposed to parse code from a module of various versions from different location. It works perfectly in regex101, but preg_match returns false, indicating an error occured. The regex you see is pulled straight from a var_dump. Also pulled from the var_dump is the string being tested. I have included the excerpt that is supposed to match it below.

    if is_set(ArchiveURL) then
        if not is_set(ArchiveDate) then
            ArchiveDate = seterror('archive_missing_date');
        end
        if "no" == DeadURL then
            local arch_text = cfg.messages['archived'];
            if sepc ~= "." then arch_text = arch_text:lower() end
            Archived = sepc .. " " .. substitute( ```

In the full block of text it takes 81,095 steps to match.  
Could it have something to do with that?
11
  • Have you looked at the output of preg_last_error()? Commented Nov 8, 2019 at 1:24
  • 3
    Have you heard about our lord and saviour, the regex /x readability flag? Commented Nov 8, 2019 at 1:25
  • @Nick it appears to return PREG_JIT_STACKLIMIT_ERROR. Though I'm not sure how to fix it. Commented Nov 8, 2019 at 1:36
  • @Cyberpower678 there's a note about disabling JIT on the constants definition page Commented Nov 8, 2019 at 1:38
  • 1
    @Nick Stackoverflow is a beautiful place. $old = ini_set( 'pcre.jit', false ); did the trick and now it's matching. :D Commented Nov 8, 2019 at 2:47

1 Answer 1

2

Getting a read from preg_last_error(), it returned 6, which maps to the constant PREG_JIT_STACKLIMIT_ERROR.

PHP 7 uses a JIT compiler for preg_match with a small stack size limit. Disabling it allows preg_match to do its job.

This can be done in the php.ini file, or on the fly in the script by using ini_set( 'pcre.jit', false );

Sign up to request clarification or add additional context in comments.

1 Comment

THANK YOU SO MUCH!!! YOU'RE A LIFE SAVER!! ALL HAIL Cyberpower678!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.