【问题标题】:preg_split results in connection resetpreg_split 导致连接重置
【发布时间】:2011-01-03 17:30:12
【问题描述】:
preg_split("/({{\s*(?:(?!}}).)+\s*}})/s", file_get_contents('data.txt'));

该行使 Apache 重置连接。 data.txt 大约为 12 kB。

我做错了什么,我可以以某种方式优化正则表达式吗?

【问题讨论】:

    标签: php regex preg-split connection-reset


    【解决方案1】:

    试试这个正则表达式:

    /({{(?>(?:[^}]|}[^}])+)}})/s
    

    主要改进:

    • (?>…) - atomic grouping 避免回溯
    • (?:[^}]|}[^}])+ – 没有环视,没有非贪婪匹配

    【讨论】:

      【解决方案2】:

      尝试将文件读入变量而不是将其传递给 preg_split。我认为是 file_get_contentsproblem rather thanpreg_split`。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-20
        • 1970-01-01
        • 2023-04-01
        • 2011-02-11
        • 2020-10-30
        • 2014-07-30
        • 1970-01-01
        相关资源
        最近更新 更多