javascript - 从 nodejs crypto 返回的字符串中 trim 非 ascii 字符

标签 javascript string node.js cryptography trim

我已经使用 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/

相关文章:

node.js - 引用组件

node.js - 未满足的 WebPack 对等依赖问题

node.js - Nuxt run dev fatal error ,状态码 500

javascript - 将表单字段值一起添加到表单提交的隐藏字段中(js 或 jquery)

javascript - toDataURL ("image/png") 到 Facebook 上传

Javascript : call() , apply() 而不是 bind() 方法

c - 在纯 C 函数中使用字符串作为结构名称的可变部分

c++ string.compare 不接受空格字符

javascript - 如何将匿名函数初始化为变量并稍后使用它?

javascript - 优化字符串匹配算法