Can someone provide a regular expression to search and replace illegal characters found
Example, removing �
I am not sure how many types of \'illegal\' char
Instead of having a blacklist, you could use a whitelist. e.g. If you want to only accept letters, numbers, space, and a few punctuation characters, you could do
myString.replace(/[^a-z0-9 ,.?!]/ig, '')
Invalid characters get converted to 0xFFFD on parsing, so any invalid character codes would get replaced with:
myString = myString.replace(/\uFFFD/g, '')
You can get all types of invalid sorts of chars here
Try this, it will work for all unexpected character like ♫ ◘ etc...
dataStr.replace(/[\u{0080}-\u{FFFF}]/gu,"");