Karp

Warning: preg_match(): Compilation failed: PCRE does not support \L, \l, \N{name}, \U, or \u at offset
匹配中文字符正则表达式抛错[\u4e00-\u9fa5]{2,4}如上 [u4e00-u9fa5]可以匹配中文,但...
扫描右侧二维码阅读全文
16
2020/09

Warning: preg_match(): Compilation failed: PCRE does not support \L, \l, \N{name}, \U, or \u at offset

匹配中文字符正则表达式抛错

[\u4e00-\u9fa5]{2,4}

如上 [u4e00-u9fa5]可以匹配中文,但是PHP又不支持

可以使用 [\x80-\xff]{2,4} 支持匹配全角字符.

知道了php中utf-8编码下用正则表达式匹配汉字的最终正确表达式——/^[\x{4e00}-\x{9fa5}]+$/u

Last modification:September 16th, 2020 at 03:53 am

Leave a Comment