So right now, re.sub does this:
>>> re.sub("DELETE THIS", "", "I want to DELETE THIS472 go to DON'T DELETE THIS847 the supermarket")
"I want to go to DON'T the supermarket"
I want it to instead delete only the first instance of “DELETE THISXXX,” where XXX is a number, so that the result is
"I want to go to DON'T DELETE THIS847 the supermarket"
The XXX is a number that varies, and so I actually do need a regex. How can I accomplish this?
As written in the documentation for
re.sub(pattern, repl, string, count=0, flags=0)you can specify thecountargument in:if you only give a count of 1 it will only replace the first