RegEx l33t 说话识别器?

RegEx l33t speak recognizer?

我知道有人问过类似的问题,但这个问题更具体。

我有一个接受用户输入的网站,但需要过滤掉一些词。例如,让我们使用示例这个词。 3 可以代替 e,4 可以代替 a,我可以很容易地根据具体情况构建一些东西来捕捉它 Seen Here,但我不知道如何使用单词数据库来做到这一点。

我有一个包含禁忌词列表的 txt 文件,可以让它过滤它们,但如果有人键入 3x4mpl3,那将被排除。

过滤器的代码是:

async function isinapropriate(text) {
    const fileStream = fs.createReadStream(__dirname + "/disabledwords.txt");
    const rl = readline.createInterface({
      input: fileStream,
      crlfDelay: Infinity
    });
    for await (const line of rl) {
      if (
        new RegExp("(^| )" + line + "($| )", "g").test(
          text
            .split(": ")
            .slice(1)
            .join(": ")
        )
      ) {
        console.log(text);
        console.log("Word: " + line);
        return true;
      }
    }
    return false;
  }

如何获取它以便将 ex4mple 识别为示例?

此外,它区分大小写,因此如果示例在数据库中,eXaMpLe 仍然有效。有没有办法解决 that?还有最后一个问题(抱歉),e x a m p l e 也有效,我知道解决方案涉及 \s 或其他问题,但我无法解决它。

编辑

我正在编写的应用程序是一个 forum/chatroom 应用程序。唯一的用户输入是他们 post

与其尝试为白名单中的每个单词创建正则表达式,不如首先规范化输入单词:

function normalize(inp) {
    const leet = {
        "1": "l",
        "3": "e",
        "4": "a",
        "5": "s",
        "7": "t",
        "0": "o"
    };
    // get rid of leetspeak
    for (let num in leet) {
        inp = inp.replaceAll(num, leet[num]);
    }
    // get rid of casing
    inp = inp.toLowerCase();
    // get rid of non-alphanumeric characters
    inp = inp.replace(/\W/g, "");
    return inp;
}

// all "example"
normalize("3x4mpl3");
normalize("e x a m p l e");
normalize("ExaMplE");