I'm trying to search and extract the sentences that start with a particular keyword, and which exist between/starts/ends with a keyword. The intention is to extract sentences starting with 'ALTER TABLE', which are either nested between 'GO' keyword or have GO on begin or end block of it. The number of sentences that exist between GO keyword could be arbitrary. Here is my sample file and the code that was written to achieve it. I'm trying to search and extract the sentences