I would like to find the last line matching a certain pattern, in python. What I am trying to do is find the last line that contains a certain item (line_end), and insert a block of information as a few new lines after it. So far I have:
text = open( path ).read()
match_found=False
for line in text.splitlines():
if line_pattern in line:
match_found=True
if not match_found:
(line_end='</PropertyGroup>
' and not sure how to use regex even with nice search words)
Can somebody help with advice on how to find the last search item, and not go beyond, so that I can insert a block of text right there ?
Thank you.