@@ -282,7 +282,7 @@ def reconfig(self, file, pattern, replacement):
282282 # Not found; append (silently)
283283 self .write_text_file (file , replacement , append = True )
284284
285- def pattern_search (self , location , pattern , multi_line = False ):
285+ def pattern_search (self , location , pattern , multi_line = False , return_match = False ):
286286 """
287287 Similar to grep, but uses pure python
288288 multi_line will search the entire file as a large text glob,
@@ -296,13 +296,17 @@ def pattern_search(self, location, pattern, multi_line=False):
296296 if self .exists (location ) and not self .isdir (location ):
297297 if multi_line :
298298 with open (location , "r+" , encoding = "utf-8" ) as file :
299- if re .search (pattern , file .read (), flags = re .DOTALL ):
299+ match = re .search (pattern , file .read (), flags = re .DOTALL )
300+ if match :
300301 found = True
301302 else :
302303 for line in fileinput .FileInput (location ):
303- if re .search (pattern , line ):
304+ match = re .search (pattern , line )
305+ if match :
304306 found = True
305-
307+ break
308+ if return_match :
309+ return match
306310 return found
307311
308312 def pattern_replace (self , location , pattern , replace = "" , multi_line = False ):
0 commit comments