Refactor escape regex, remove useless code