yuweijun'blog
Tuesday, June 10, 2008
如何用ruby验证字符串中是否包括中文字
def include_chinese_char?(str)
# /[\u4e00-\u9fa5]/ unicode 中文字符集范围 即: 一-龥
/[一-龥]/ =~ str
end
puts include_chinese_char?("ruby regexp.")
puts include_chinese_char?("中 ruby regexp.")
puts include_chinese_char?("ruby 中 regexp.")
# >> nil
# >> 0
# >> 5
No comments:
Post a Comment
‹
›
Home
View web version
No comments:
Post a Comment