Regular expression to extract whole sentences with matching word
I would like to extract sentences with the word "flung" throughout the text.
For example, in the following text I would like to extract the sentence "It was exactly as if the hand grabbed them in the center and threw them aside." using a regular expression.
I tried using this one .*? flung (?<sub>.*?)\.
, but it starts searching from the beginning of the string.
How can I solve the problem?
How she did it, the most unusual thing happened. The linens came together, suddenly jumped into some kind of peak, and then jumped onto the lower rail. As if a hand grabbed them in the center and threw them aside. Right after,.........
source to share
(?<=^|\s)[A-Z][^!?.]*( word\s*)[^!?.]*(?=\.|\!|\?)
The beginning of the line or space begins before the first capital letter, then it can contain any unset characters [!?.](*)-
or cannot, then contains your target word with or without white spaces (if it is at the end of the sentence), then it can contain any unset characters again [!?.](*)-
or not, and finally ends with a dot or !
or ?
,
source to share