Can you make a regex to match two statements if they occur within N lines of each other?

I am looking through a code base for a specific if statement used as a gate, that is followed by a certain function. IE if global_var contains test.check()

if global_var:
   fizz()
   test.buzz()
   test.check()
   bang()
   bop()

would match but not any of the following

fizz()
test.buzz()
test.check()
bang()
bop()
if global_var:
   fizz()
   test.buzz()
   bang()
   bop()

If possible, I would like to do so in the search bar of my IDE or github website, not with another script. So a Regex implementation would be ideal. I figure that a Regex that matches two different strings with N lines of each other could be possible, and applicable in this circumstance given we have a 30 line limit on how long functions can be; but I do not know how to write a statement that checks across multiple lines of code after the first match, or how to limit it not to go to the end of the file.

Is this something that is possible with regex? If so, could i get a generic example/explanation to help me understand how? If not I will consign myself to writing another bash script to do this search.

Read more here: Source link