PHP 尽管在 regex101 中成功匹配,但正则表达式不起作用

PHP regex not working, despite successfully matching in regex101

我遇到了最奇怪的问题。我尝试在这里引用其他类似的答案,但 none 似乎解决了我的问题。

我在 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

我知道这是一个混乱的正则表达式,它应该从不同位置的不同版本的模块中解析代码。在regex101中完美运行,但是preg_match returns false,说明出错了。您看到的正则表达式是直接从 var_dump 中提取的。同样从 var_dump 中提取的是正在测试的字符串。我在下面包含了应该与之匹配的摘录。

    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?

从 preg_last_error() 读取,它返回 6,它映射到常量 PREG_JIT_STACKLIMIT_ERROR。

PHP 7 使用 JIT 编译器 preg_match 具有较小的堆栈大小限制。禁用它允许 preg_match 完成它的工作。

这可以在 php.ini 文件中完成,或者使用 ini_set( 'pcre.jit', false );

在脚本中即时完成