There are 2 different characters we use for replacements, so 2 replace statements are needed. Most characters are replaced with underscores, just colons are replaced with hashes. I did this as it was a replacement that we've use previously in the portal for this use case.