0

可以说我有代码:

str = "foobar"
print "Enter in the letters you would like to match: "
match = gets
# Pseudocode:
str =~ /[match]/

我不想匹配整个字符串:match,我只想匹配每个字母,例如:

str =~ /[aeiou]/

会产生元音。我该如何做才能匹配用户输入的字母?

4

1 回答 1

2

试试这个:

match = gets.chomp # cut off that trailing \n
str =~ /[#{match}]/
于 2012-04-08T17:51:44.640 回答