判断 拼音的正则
- 作者: 亖呉?盀
- 来源: 51数据库
- 2022-08-12
#区分拼音和英文的代码
#拼音正则1
R = /(b|p|m|f|d|t|n|l|g|k|h|j|q|x|zh|ch|sh|r|z|c|s|y|w)(a|o|e|i|u|ao|iu|ei|ui|ou|iu|ie|an|en|in|un|ang|eng|ing|ong)/i
class String
def is_py
self.match(/^(#{R}\s?)+$/)
end
end
s=[]
s << 'wo shi ji qi ren'
s << 'zheshi pinyin'
s << 'show me the money'
s << 'this is english '
s.each{|x| print x, " : " , x.is_py ? 'y':'n', "\n" }
#wo shi ji qi ren : y
#zheshi pinyin : y
#show me the money : n
#this is english : n
推荐阅读
