Add an optional replacement string for unsafe characters

Sometimes it useful to replace unsafe characters with a replacement like _ for example.