update regex to replace invalid char at the right place.