Strip out special characters from a string

I think the title is pretty self explanatory, but I’m hoping someone has a much better idea (both performance and code maintainability-wise) to remove characters from a string.

What I’m looking to do is take any string and remove any characters other than A-Z, 0-9 or whitespace. Ex. “Hello: World!” would become “Hello World”. The only approach that I can think of at the moment is to have a stack of ReplaceAll()'s, but I was wondering if there was a better approach or if there’s a Regex approach that I’ve not thought of yet.

Thanks!


regex = CreateObject("roRegex", "[^a-zA-Z0-9\s]", "")
clean = regex.ReplaceAll(dirty, "")

–Mark

Thanks Mark! That was exactly what I was looking for!