Use regex to replace illegal characters.