如何定义字符串中的最后一个元音?
例如,我有一个词“经典”
我想找到单词“class”的最后一个元音ic" 是字母 "i",并删除最后一个元音。
我在想 :
def vowel(str)
result = ""
new = str.split(" ")
i = new.length - 1
while i < new.length
if new[i] == "aeiou"
new[i].gsub(/aeiou/," ")
elsif new[i] != "aeiou"
i = -= 1
end
end
return result
end
r = /
.* # match zero or more of any character, greedily
\K # discard everything matched so far
[aeiou] # match a vowel
/x # free-spacing regex definition mode
"wheelie".sub(r,'') #=> "wheeli"
"though".sub(r,'') #=> "thogh"
"why".sub(r,'') #=> "why"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)