Replace sed with python script

sed escaping is wrong: e.g. re.escape() will escape `+`, but with BRE escaped 
plus is quantifier