Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可以说我有代码:
str = "foobar" print "Enter in the letters you would like to match: " match = gets # Pseudocode: str =~ /[match]/
我不想匹配整个字符串:match,我只想匹配每个字母,例如:
str =~ /[aeiou]/
会产生元音。我该如何做才能匹配用户输入的字母?
试试这个:
match = gets.chomp # cut off that trailing \n str =~ /[#{match}]/