我有这样的字符串
the horse and the hound and the horn that belonged to
如何获取字符串中单词后面的所有单词?所以它像这个一样返回
the horse, the hound, the horn
您可以使用String#scan
来获取每个";加上后面跟着任何单词的空白,然后join
这些结果:
"the horse and the hound and the horn that belonged to".scan(/bthe w+/).join(", ")
# "the horse, the hound, the horn"