Regular expression to extract whole sentences with matching word

前端 未结 4 932
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 06:20

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

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 06:30

    (?<=^|\s)[A-Z][^!?.]*( word\s*)[^!?.]*(?=\.|\!|\?)
    

    Before first capital letter there is a line start or a white space, then it may consist any characters without set of [!?.](*)-or may not , then contains your target word with or without white spaces after it (if it is in the end of the sentence), then may consist again any characters without set of [!?.](*)-or not, and finally ends with dot or ! or ?.

提交回复
热议问题