假设我有代码:
str = "foobar"
print "Enter in the letters you would like to match: "
match = gets
# Pseudocode:
str =~ /[match]/
我不想匹配整个字符串:匹配,我只想匹配每个字母,例如:
str =~ /[aeiou]/
会产生元音。 我该怎么做才能匹配用户输入的字母?
答案 0 :(得分:2)
试试这个:
match = gets.chomp # cut off that trailing \n
str =~ /[#{match}]/