Fixed efficiency and recursivity for RegEx replacement