【发布时间】:2019-11-08 01:22:29
【问题描述】:
我遇到了最奇怪的问题。我试过在这里参考其他类似的答案,但似乎没有一个能解决我的问题。
我在 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 返回 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()的输出了吗? -
你听说过我们的救世主,正则表达式
/x可读性标志吗? -
@Nick 它似乎返回 PREG_JIT_STACKLIMIT_ERROR。虽然我不确定如何解决它。
-
@Cyberpower678 在常量定义 page 上有一个关于禁用
JIT的注释 -
@Nick Stackoverflow 是一个美丽的地方。 $old = ini_set('pcre.jit', false );成功了,现在它匹配了。 :D