正则表达式提取具有匹配单词的整个句子 [英] Regular expression to extract whole sentences with matching word

查看:85
本文介绍了正则表达式提取具有匹配单词的整个句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在整个文本中提取带有flung"一词的句子.

I would like to extract sentences with the word "flung" in the whole text.

例如,在下面的文本中,我想提取句子就好像一只手抓住了它们的中心并将它们扔到了一边."使用正则表达式.

For example, in the following text, I'd like to extract the sentence "It was exactly as if a hand had clutched them in the centre and flung them aside." using regular expression.

我尝试使用这个 .*?抛出 (?.*?)\.,但它从行的开头开始搜索.

I tried to use this .*? flung (?<sub>.*?)\., but it starts searching from the beginning of the line.

我该如何解决问题?

就在她这样做的时候,一件最不寻常的事情发生了.被褥聚拢在一起,猛地一跃而起,变成了一座山峰,然后一头扎进了底栏.就好像一只手将他们抓在了中间,然后扔到了一边.紧接着,…………

As she did so, a most extraordinary thing happened. The bed-clothes gathered themselves together, leapt up suddenly into a sort of peak, and then jumped headlong over the bottom rail. It was exactly as if a hand had clutched them in the centre and flung them aside. Immediately after, .........

推荐答案

给你,

[^.]* flung [^.]*\.

演示

[^.?!]*(?<=[.?\s!])flung(?=[\s.?!])[^.?!]*[.?!]

演示

这篇关于正则表达式提取具有匹配单词的整个句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆