本文介绍了使用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;
是的,.
匹配一个字符.split DWYM 的空模式:
Yes, .
matches one character. The empty pattern for split DWYM:
use utf8;
split //, '冰淇淋'
# returns ('冰', '淇', '淋')
这篇关于使用perl检测汉字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!