How is it possible to obtain the line numbers of all the text snippets matching a given regexp, within a file?
regexp
file_content = f.rea
with open(somefile, 'r') as f: line_numbers = [n for n, line in enumerate(f) if re.search(someRegexp, line)]
import re reg="ha*" count=0 f = open(somefile,'r') while True: line= f.readline() if not line: break else: count+=1 if re.search(reg,line): print count,line