使用Perl检测中文字符? [英] Detect chinese character using perl?
本文介绍了使用Perl检测中文字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以使用Perl检测汉字吗?以及如何用符号点."分隔汉字?完美吗?
Is there any way to detect Chinese characters using Perl? And is there any way on how to split Chinese characters with symbol dot '.' perfectly?
推荐答案
取决于您对汉字的特殊理解.也许您正在寻找/\p{Script=Hani}/
,但是如果我们要扩大网络宽度,则以下正则表达式模式将匹配中文书写中出现的内容.如有必要,请限制.
Depends on your particular notion of what is a Chinese character. Perhaps you're looking for /\p{Script=Hani}/
, but if we want to cast our net wide, the following regex pattern will match stuff that occurs in Chinese writing. Restrict if necessary.
use 5.014;
/
(?: \p{Block=CJK_Compatibility}
| \p{Block=CJK_Compatibility_Forms}
| \p{Block=CJK_Compatibility_Ideographs}
| \p{Block=CJK_Compatibility_Ideographs_Supplement}
| \p{Block=CJK_Radicals_Supplement}
| \p{Block=CJK_Strokes}
| \p{Block=CJK_Symbols_And_Punctuation}
| \p{Block=CJK_Unified_Ideographs}
| \p{Block=CJK_Unified_Ideographs_Extension_A}
| \p{Block=CJK_Unified_Ideographs_Extension_B}
| \p{Block=CJK_Unified_Ideographs_Extension_C}
)
/x;
是,.
匹配一个字符. 拆分 DWYM的空模式:
Yes, .
matches one character. The empty pattern for split DWYM:
use utf8;
split //, '冰淇淋'
# returns ('冰', '淇', '淋')
这篇关于使用Perl检测中文字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文