dsphper
V2EX  ›  问与答

PHP 正则引擎 bug,通杀 PHP 所有版本。

  •  
  •   dsphper · Aug 11, 2020 · 2805 views
    This topic created in 2275 days ago, the information mentioned may be changed or developed.
    
    $re = '/@([^@\s::]+)[:| |:]+/m';
    $str = '@多阿斯顿撒 2111 撒奥:asdsada @asdsadsadsad 阿斯顿撒大:@阿斯顿撒大所:@阿斯顿撒多撒多撒 sad 撒大撒多';
    
    preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
    
    // Print the entire match result
    var_dump($matches);
    
    

    测试了下所有版本的 php 解析的结果都是错误的,其他语言 Python,Js 等可以正常解析。

    错误的结果

    aLNbex.png

    正确的解析结果

    aLUSld.png

    9 replies  •  2020-08-11 19:57:04 +08:00
    gz911122
    gz911122
    Aug 11, 2020
    1
    截图的那个正则网站是啥, 看起来不错啊
    dsphper
    dsphper
    OP
    Aug 11, 2020
    2
    @gz911122 regex101
    CismonX
    CismonX
    Aug 11, 2020❤️5
    3
    这个是引擎不识别 unicode 字符的问题。改成:

    $re = '/(*UTF8)@([^@\s::]+)[:| |:]+/m';

    就没问题了。
    iyaozhen
    iyaozhen
    Aug 11, 2020❤️1
    4
    不要见风就是雨

    /u
    才能识别中文
    vc1
    vc1
    Aug 11, 2020
    5
    执行 php 代码的图是哪个网站
    dsphper
    dsphper
    OP
    Aug 11, 2020
    6
    @iyaozhen
    以感谢老哥
    dsphper
    dsphper
    OP
    Aug 11, 2020
    7
    @CismonX 4 楼老哥解决方法简单粗暴。
    dsphper
    dsphper
    OP
    Aug 11, 2020
    8
    @vc1 3v4l
    azh7138m
    azh7138m
    Aug 11, 2020 via iPhone
    9
    @iyaozhen 不要见着风是得雨

    你们这样子不行的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1415 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 108ms · UTC 18:24 · PVG 02:24 · LAX 10:24 · JFK 13:24
    ♥ Do have faith in what you're doing.