but it is also matching the text inside tag1 with the tag2 and while replacment, it is removing those text. Since the text inside tag1 is of variable length so not able to use the lookbehind as it doesnt support variable length lookbehind.
Please suggest some alternative for this or if i am missing somthing. Thanks
One way to do this would be to read a tags file into a list object, then manipulate said object in anyway you choose.
As a POC:
The input file
sometext with multiple lines goes here
with open("tags", mode='r', encoding='UTF-8') as file:
tags = file.readlines()
tags = [tag.strip() for tag in tags] # clean it
ip = tags.rstrip(">").split()
tags = ip
# just see the results
for tag in tags:
Once you have that, the list object can be used to produce an output file, or whatever.