Reputation: 1675
I have successfully decrypted a sensitive data using nodejs crypto library.
The problem is that the decrypted data has a trailing non-ascii characters.
How do I trim that?
My current trim function I below does not do the job.
String.prototype.fulltrim = function () {
return this.replace( /(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '' ).replace( /\s+/g, ' ' );
};
Upvotes: 4
Views: 7390
Reputation: 14935
I think following would be suffice.
str.replace(/[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, '') ;
Upvotes: 5
Reputation: 1692
Based on this answer, you can use:
String.prototype.fulltrim = function () {
return this.replace( /([^\x00-\xFF]|\s)*$/g, '' );
};
This should remove all spaces and non-ascii characters at the end of the string, but leave them in the middle, for example:
"Abcde ffאggg ג ב".fulltrim();
// "Abcde ffאggg";
Upvotes: 0