Improved regex handling