Fixed regex safety check