正则表达式:将匹配的单词返回到下一个句号

时间:2017-10-02 17:34:23

标签: regex

我想返回关键词,一切都在继续,直到它达到第一个可能的句号。例如,如果句子是

The house was full of tables and chairs. He did not like them. 

如果关键词是房子,我想返回

house was full of tables and chairs. 

非常感谢!

2 个答案:

答案 0 :(得分:2)

你可以使用正则表达式

house[^\.]+\.

请参阅regex101 demo

答案 1 :(得分:2)



var text = "The house was full of tables and chairs. He did not like them."
var match = text.match(/house[^.]*\./)
var res = match && match[0]
console.log(res)