使用正则表达式匹配utf-8编码的任意汉字 [英] Use regular expression to match ANY Chinese character in utf-8 encoding
本文介绍了使用正则表达式匹配utf-8编码的任意汉字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
比如我想把一个m
组成的字符串匹配到n
个汉字,那么我可以使用:
For example, I want to match a string consisting of m
to n
Chinese characters, then I can use:
[single Chinese character regular expression]{m,n}
是否有单个汉字的正则表达式,可以是任何存在的汉字?
Is there some regular expression of a single Chinese character, which could be any Chinese characters that exists?
推荐答案
匹配中文(好吧,CJK)字符的正则表达式是
The regex to match a Chinese (well, CJK) character is
p{script=Han}
可以简单地理解为
p{Han}
这假设您的正则表达式编译器满足要求RL1.2来自UTS#18的属性Unicode 正则表达式.Perl 和 Java 7 都符合该规范,但许多其他版本不符合.
This assumes that your regex compiler meets requirement RL1.2 Properties from UTS#18 Unicode Regular Expressions. Perl and Java 7 both meet that spec, but many others do not.
这篇关于使用正则表达式匹配utf-8编码的任意汉字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文