我需要使用下面的正则表达式来验证一些亚洲字符
$regexp = "/^[\-'\u2e80-\u9fff\sa-zA-Z.]+$/"; // with warning
$regexp = "/^[\-'\sa-zA-Z.]+$/"; // without warningpreg_match()函数.preg-match:编译失败: PCRE不支持\L、\l、\N、\P、\p、\U、\u或\X。
您知道如何更改正则表达式模式以便验证\u2e80-\u9fff中的亚洲字符吗
我使用的是最新的XAMPP
Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1发布于 2010-08-22 01:14:47
不支持\uXXXX语法。请改用\x{XXXX}。参见here。
您的\u2e80-\u9fff范围也等同于
\p{InCJK_Radicals_Supplement}\p{InKangxi_Radicals}\p{InIdeographic_Description_Characters}\p{InCJK_Symbols_and_Punctuation}\p{InHiragana}\p{InKatakana}\p{InBopomofo}\p{InHangul_Compatibility_Jamo}\p{InKanbun}\p{InBopomofo_Extended}\p{InKatakana_Phonetic_Extensions}\p{InEnclosed_CJK_Letters_and_Months}\p{InCJK_Compatibility}\p{InCJK_Unified_Ideographs_Extension_A}\p{InYijing_Hexagram_Symbols}\p{InCJK_Unified_Ideographs}
如果您使用的是UTF-8,不要忘记添加u修饰符(/regex here/u)。如果您正在处理另一种多字节编码,则必须首先将其convert为UTF-8。
发布于 2018-09-10 11:34:28
'/^[<\x{4e00}-\x{9fa5}>]+$/u';试试这个吧。PHP不支持上面发布的正则表达式,但Javascript支持该表达式。
https://stackoverflow.com/questions/3538293
复制相似问题