gpt4 book ai didi

PHP preg_match 长度 3276 限制

转载 作者:可可西里 更新时间:2023-11-01 13:00:11 26 4
gpt4 key购买 nike

在某些情况下,PHP 的 preg_match 似乎对匹配重复字符有 3276 个字符的限制。

^(.|\s){0,3276}$ 有效,但 ^(.|\s){0,3277}$ 无效。

它似乎并不总是适用,因为 /^(.){0,3277}$/ 有效。

我无法在 PHP 文档或错误跟踪器中的任何地方找到它。数字 3276 似乎有点奇怪,我唯一能想到的是它大约是 32767 的 1/10,这是有符号 16 位整数的极限。

preg_last_error() 返回 0。

我已经在 http://www.phpliveregex.com/ 上重现了这个问题以及我的本地系统和网络服务器。

编辑:看起来我们从代码中得到“警告:preg_match():编译失败:正则表达式在偏移量 16 处太大”,所以它看起来与 PHP preg_match_all limit 是同一个问题。 .

但是,正则表达式本身不是很大...当您有重复的组使其太大时,PHP 是否会进行某种扩展?

最佳答案

为了处理与 Perl 兼容的正则表达式,PHP 只是捆绑了一个 third-party library负责这项工作。您描述的行为实际上是 documented :

The "*" quantifier is equivalent to {0,} , the "+" quantifier to {1,} , and the "?" quantifier to {0,1} . n and m are limited to non-negative integral values less than a preset limit defined when perl is built. This is usually 32766 on the most common platforms.

所以总是有一个硬性限制。为什么您的测试表明 PHP 限制比典型限制小 10 倍?不知道:)

关于PHP preg_match 长度 3276 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17926195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com