一个正则表达式匹配两个单词之间的所有条件

时间:2017-10-09 04:52:19

标签: javascript

我需要匹配(单词)...... ......之间的一切......(第一名:(或))

实施例

输入
您可以开车去机场或乘坐出租车但不要在那里散步或骑自行车。

匹配
你可以either开车到机场or乘坐出租车,但不要在那里散步或骑自行车。

输出
either开车前往机场or


我尝试了什么

(either\s).*(\sor)
但它不会得到第一个或......



a = "You can either drive to the airport or get a taxi but don't walk or bike there."
b = /(either\s).*(\sor)/g.exec(a)
console.log(b[0])




1 个答案:

答案 0 :(得分:1)

您正在寻找的是:

/(either\s).+?(\sor)/g



a = "You can either drive to the airport or get a taxi but don't walk or bike there."
b = /(either\s).+?(\sor)/g.exec(a)
console.log(b[0])