我需要使用下面的正则表达式来验证一些亚洲字符
$regexp = "/^[\-'\u2e80-\u9fff\sa-zA-Z.]+$/"; // with warning
$regexp = "/^[\-'\sa-zA-Z.]+$/"; // without warning
preg_match() [function.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
最佳答案
PCRE 不支持 \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。
关于regex - 正则表达式 - PCRE 不支持\L,\l,\N,\P,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3538293/