标签: ruby regex gsub
我有许多简单的字符串'som', 'man', 'pal'等 我如何制作元音字符upcase!,让元音正则表达式或数组输出如'sOm','pAl','mAn'?
'som', 'man', 'pal'
upcase!
答案 0 :(得分:7)
"som".gsub(/[aeiou]/, &:upcase) # => "sOm"
或
"som".tr("aeiou", "AEIOU") # => "sOm"