I wrote a script as shown below, I want to replace the strings between StartNum and /StartNum by another variable n. How do I define the position between these two strings in Python?
f1 = open('name.txt', 'r')
f2 = open('result.txt', 'w')
n=5000
for line in f1:
f2.write(line.replace('(StartNum)(.*)(/StartNum)',str(n)))
if "StartNum" in line:
n=n+1
This replaces
bworpwithboop, so the final string it returns isStartNumboop/StartNum.