我已经使用 nodejs 加密库成功解密了敏感数据。
问题是解密后的数据有尾随非 ascii 字符。
我该如何 trim 它?
我下面的当前 trim 功能无法完成这项工作。
String.prototype.fulltrim = function () {
return this.replace( /(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '' ).replace( /\s+/g, ' ' );
};
最佳答案
我认为以下就足够了。
str.replace(/[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, '') ;
关于javascript - 从 nodejs crypto 返回的字符串中 trim 非 ascii 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11498229/