修剪nodejs crypto返回的字符串中的非ascii字符

ian*_*ian 4 javascript string cryptography trim node.js

我已经使用nodejs加密库成功解密了敏感数据.

问题是解密的数据有一个尾随的非ascii字符.

我该如何修剪?

我下面的当前修剪功能不起作用.

String.prototype.fulltrim = function () {
  return this.replace( /(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '' ).replace( /\s+/g, ' ' );
};
Run Code Online (Sandbox Code Playgroud)

Ana*_*and 5

我认为以下就足够了.

str.replace(/[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, '') ; 
Run Code Online (Sandbox Code Playgroud)