improved regex handling