If I remove the \n after the b I get the string REPLACED. However I need to replace newlines and I thought M and S flag would let dot match and replace a multiline string but it appears not to
re.sub(r"aA.*Z", "REPLACED", "aAb\nZ\n//ok", re.M|re.S)
The real data I’d like to replace is "^void c_like_func_NAME(){…}". I believe I can figure out the rest once I can replace across lines
>Solution :
Your logic is correct, but it appears that you need to explicitly specify the flags field in the 4th parameter. Hence, the following works:
print(re.sub(r"aA.*Z", "REPLACED", "aAb\nZ\n//ok", flags=re.M|re.S))
This prints:
REPLACED
//ok