查找字符串 Ruby 中单词"The"后的所有单词



我有这样的字符串

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"

相关内容

最新更新