首页 > 解决方案 > 为什么在 neofetch 上使用 npm 包 ansi-regex 时不过滤“99D”?

问题描述

我正在尝试制作一个 API,它使用https://github.com/chalk/ansi-regex从请求正文中删除 ANSI 转义序列。特快路线如下:

const pattern = [
  '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
  '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
].join('|');
let ansiRegex = new RegExp(pattern, 'g'); // This code is the main part of chalk/ansi-regex

app.post("/unesc", (req, res) => res.send(req.body.replace(ansiRegex, "")))

这在 99% 的时间里都有效,但如果我用neofetch字符串来做的话99D

终端截图

这也是作为文本文件的直接 neofetch 输出:https ://gofile.io/d/eShH4X

这是某种非标准的转义序列还是 ansi-regex 是错误的?

标签: javascriptbashexpressansi-escapeunicode-escapes

解决方案


推荐阅读