本文介绍了正则表达式 - PCRE 不支持 \L、\l、\N、\P、的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用以下正则表达式来验证一些亚洲字符

 $regexp = "/^[\-'\u2e80-\u9fff\sa-zA-Z.]+$/";//有警告$regexp = "/^[\-'\sa-zA-Z.]+$/";//没有警告

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.

谢谢

解决方案

PCRE 不支持 \uXXXX 语法.使用 \x{XXXX} 代替.请参阅此处.

你的 \u2e80-\u9fff 范围也相当于

\p{InCJK_Radicals_Supplement}\p{InKangxi_Radicals}\p{InIdeographic_Description_Characters}\p{InCJK_Symbols_and_Punctuation}\p{InHiragana}\p{InKatakana}\p{InBopomofoang_Characters}\p{InBopomofoang_Characters}\}\p{InBopomofo_Extended}\p{InKatakana_Phonetic_Extensions}\p{InEnclosed_CJK_Letters_and_Months}\p{InCJK_Compatibility}\p{InCJK_Unified_Ideographs_Extension_A}\p{InYijing_Hexagrams_Extension_A}\p{InYijing_Hexagram}\P{InYijing_Hexagram}\

如果您正在处理 UTF-8,请不要忘记添加 u 修饰符(/regex here/u).如果您正在处理另一种多字节编码,则必须先将其转换为 UTF-8.

I need to use the following regular expression to validate some Asian characters

 $regexp = "/^[\-'\u2e80-\u9fff\sa-zA-Z.]+$/"; // with warning

 $regexp = "/^[\-'\sa-zA-Z.]+$/";   // without warning

preg_match() [function.preg-match]: Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X.

Do you know how to change the regular expression pattern so that I can validate the Asian characters from \u2e80-\u9fff

I am using the latest 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

Thank you

解决方案

PCRE does not support the \uXXXX syntax. Use \x{XXXX} instead. See here.

Your \u2e80-\u9fff range is also equivalent to

\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}

Don't forget to add the u modifier (/regex here/u) if you're dealing with UTF-8. If you're dealing with another multi-byte encoding, you must first convert it to UTF-8.

这篇关于正则表达式 - PCRE 不支持 \L、\l、\N、\P、的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 13:08