var desired = stringToReplace.replace(/[^\w\s]/gi, '')
As was mentioned in the comments it's easier to do this as a whitelist - replace the characters which aren't in your safelist.
The caret (^) character is the negation of the set [...], gi say global and case-insensitive (the latter is a bit redundant but I wanted to mention it) and the safelist in this example is digits, word characters, underscores (\w) and whitespace (\s).
var desired = stringToReplace.replace(/[^\w\s]/gi, '')
As was mentioned in the comments it's easier to do this as a whitelist - replace the characters which aren't in your safelist.
The caret (^) character is the negation of the set [...], gi say global and case-insensitive (the latter is a bit redundant but I wanted to mention it) and the safelist in this example is digits, word characters, underscores (\w) and whitespace (\s).
Note that if you still want to exclude a set, including things like slashes and special characters you can do the following:
var outString = sourceString.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
take special note that in order to also include the "minus" character, you need to escape it with a backslash like the latter group. if you don't it will also select 0-9 which is probably undesired.
Efficient way of replacing special characters - JavaScript - SitePoint Forums | Web Development & Design Community
How to remove a special characters in a given string by regex
Remove special characters
How to remove special characters and codes (using jQuery) from SharePoint rendered html? - SharePoint Stack Exchange
This is one of the most annoying (and there are so many to choose from) things that SP does. We have a lot of lists that are used to display information. I found that preventing the zero width characters from getting into the list items in the first place was the best way to go about it.
There are probably other ways to attack this system wide, but I add the following code to all of our new/edit forms for lists that will be used to display content.
<script type="text/javascript">
function PreSaveAction(){
// remove all the zero width spaces ​ from the fields.
jQuery('.ms-rtestate-field div[contenteditable=true]').each(function(index,element) {
var exp = new RegExp(String.fromCharCode(8203),"g");
var editor= jQuery(element);
var txt = editor.html()
txt = txt.replace(exp,'');
txt = txt.replace(/ /g,' ')
txt = txt.replace(/ {2,}/g,' ');
editor.html(txt);
});
return true;
}
</script>
This also gets rid of the non-breaking spaces and if somebody tries to line something up with a bunch of spaces. You can remove the last two txt.replace() lines if you don't want that.
We've been using this more than a year without problems in our 2013 on-prem site.
These are Unicode strings, the one you have there is space with 0 width (technically shouldn't add any width)... Microsoft's html generator adds these to control line breaks.
This will remove any non ascii characters. There may be unintended results from removing these without being more specific (so try in a test area, or better yet a development environment)
str.replace(/[^\x00-\x7F]/g, "");