example txt file :
vrf X.x.X hello ! how are you ! vrf y.y.y. hi !
I want to run through above provided text and print the output starting
The solution using re.findall() function:
import re with open('lines.txt', 'r') as fh: result = re.findall(r'vrf[^!]+(?=!)', fh.read(), re.M) print(''.join(result))
The output:
vrf X.x.X hello vrf y.y.y. hi