We need a regular expression to select sentences from a text where we are searching for a specific term or phrase. The result should have the line with the search term as well as the preceding and succeeding line. The definition of line here can be anything starting from empty line to any character.
For example if we are searching for the term “deposition”(case insensitive) in the below text:
12 xxxxxxxxxx. )
13 ______________________________)
14
15
16
17
18 VIDEOTAPE DEPOSITION OF JOHN
19 FRIDAY, OCTOBER 30, 2009
20
21
22
23
24 PAGES 1 - 92
this should return me the following result:
17
18 VIDEOTAPE DEPOSITION OF JOHN
19 FRIDAY, OCTOBER 30, 2009
Try this pattern:
Replace the word you’re looking for with
DEPOSITIONeach time. In order to make the search case insensitive, you need to set it up in the regular expression engine of your choice.Here’s a live demo.