【发布时间】:2012-01-19 10:16:58
【问题描述】:
从字符串"Fabulous two, three, or six night Stay For Two With Meals" 我想捕捉单词'night'之前的5个单词。
在这个例子中我想得到['Fabulous', 'two', 'three', 'or', 'six']
我目前正在使用s.scan(/(?:\w+)/),它返回标记化数组:
["fabulous", "two", "three", "or", "six", "night", "Stay", "For", "Two", "With", "Meals"]
然后我通过索引找到“夜晚”这个词。但是我想知道正则表达式是否也可以完成这一步。
【问题讨论】: