【问题标题】:How can I use Turkish characters in Nodejs module Regex如何在 Nodejs 模块 Regex 中使用土耳其语字符
【发布时间】:2021-09-18 22:52:37
【问题描述】:

我想使用带有土耳其字符的bad-words 模块,但我不能使用。我该怎么做?

示例:

var Filter = require("bad-words")

var filter = new Filter({ replaceRegex:  /[A-Za-z0-9가-힣_]/g }); 
//multilingual support for word filtering

filter.addWords('ğ', 'ü', 'ı', 'i', 'e', 'y');

filter.clean("Turkish: ğ ü ı English: i e y");

输出:“土耳其语:ğ ü ı 英语:* * *”

在 npm RunKit 上试用:https://npm.runkit.com/bad-words

【问题讨论】:

  • This Answer 可能会有所帮助,使用 Unicode 而不是字符。

标签: javascript node.js regex


【解决方案1】:

bad-words 库不支持非 ascii 字母,因为它使用 ascii \b 作为单词边界。非 ascii 甚至不被视为字母。

您可以看到here 的修复建议。

【讨论】:

    【解决方案2】:

    如果 RegEx 引擎支持 Unicode,那么您可以尝试匹配 unicode 而不是字符。 see here

    【讨论】:

      猜你喜欢
      • 2014-08-09
      • 2014-07-25
      • 1970-01-01
      • 2015-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      相关资源
      最近更新 更多