admin管理员组文章数量:1402855
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, ' ' );
};
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, ' ' );
};
Share
Improve this question
edited Jul 16, 2012 at 5:10
Inkbug
1,6921 gold badge11 silver badges28 bronze badges
asked Jul 16, 2012 at 4:45
ianian
1,6952 gold badges19 silver badges24 bronze badges
0
2 Answers
Reset to default 5I think following would be suffice.
str.replace(/[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, '') ;
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";
本文标签: javascripttrim nonascii characters from string returned by nodejs cryptoStack Overflow
版权声明:本文标题:javascript - trim non-ascii characters from string returned by nodejs crypto - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744285240a2598848.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论