Reading some text file by fs of node.js/Windows results awkward data that contains invisible characters.
String.length indicates the data contains many redundant invisible characters.
Trying to trim by js String.trim does not work well, so I try to remove them using String.replace with regex.
So, here's my question.
what is the regex to trim other than A-Z a-z 0-9 and symbols?
Space should be preserved (not the target to trim).
Thanks.
You could use a negated class like:
[^A-Za-z0-9\s]
Btw, you also can shorten it to:
[^A-Za-z\d\s]
And.. if you don't mind to preserve underscores your could use:
[^\w\s]
The idea of the negated class is to not match the characters in it. For this regex:
[^A-Za-z0-9\s]
it means:
^ ---> not match the following
A-Za-z ---> letters from a-z insensitive
\d ---> digits from 0 to 9
\s ---> spaces, tabs, etc (whitespaces)

Add your symbols to the class you have designated as non-replacable.
[^a-zA-Z0-9\s add symbols here]+