I have a repeating text in a large file which I want to replace with some other text. For example:
some text.......\n partition by range (STRT_DTTM)\n some more text......\n ); I want to use regex to find these blocks that start with partition by range and ends with ); and replace that block with 'THIS IS TEST'. I am using the below code import re
with open(r"C:\Users\x217838\Desktop\python\input.txt","rt") as in_file:
text = in_file.read()
s = re.compile("^partition by range(.*);\)$)",re.MULTILINE)
replace = re.sub(s, 'THIS IS TEST', text)
print(replace)
Can you please let me know where I am going wrong.