function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShowerHammerShowerHammer 

Need some help with replacing characters and regex patterns.

I currently an trying to replace all non-alphanumeric characters in a string and replacing everything but the space, would like that to be a hyphen, with a blank value to remove it and cannot figure out how to escape out commas, parenthesis, apostrophes, periods and colons.

The strings I am parsing could have any one of the characters below in them.

This is what I am using:
foo = foo.replaceAll('[\\,"\\:~|!|@|#|$|%|^|&|*|_|+|=|<|>|?\\(\\)\\{\\}\\;\\\']', '');
foo = foo.replaceAl(' ','-');
 
I have tried using but cannot get this to work either.
foo = foo.replaceAll('![a-zA-Z0-9]', '');
Any help would be appreciated.
kroberts31.3887885794840894E12kroberts31.3887885794840894E12
What kind of error, or failure, are you getting. The first two lines of code you supplied do what you want, except that:
1. The first line doesn't have an "|.", so periods are eliminated.
2. The second line is missing an "l" in the replaceAll method name and would throw a compilation error.