I am parsing a series of text files for some patterns, since I want to extract them to other file.
A way to say it is that I would like to "remove" everything except the matches from the file.
For example, if I have pattern1, pattern2, pattern3 as matching patterns, I'd like the following input:
bla bla
pattern1
pattern2
bla bla bla
pattern1
pattern3
bla bla bla
pattern1
To give the following output:
pattern1
pattern2
pattern1
pattern3
pattern1
I can use re.findall
and successfully get the list of matches for any pattern, but I cannot think of a way to KEEP THE ORDER considering the matches of each pattern are mixed inside the file.
Thanks for reading.