【问题标题】:Regex to Detect Zalgo正则表达式检测 Zalgo
【发布时间】:2026-01-11 05:30:02
【问题描述】:

我正在创建一个消息过滤系统,用于检测 z͎͗ͣḁ̵̑l̉̃ͦg̐̓̒o͓̔ͥ。

我当前的正则表达式是/([^\u0009-\u02b7\u2000-\u20bf\u2122\u0308]|(?![^aeiouy])\u0308)/gm 但这也捕获了表情符号。

Regex应该过滤所有W̵̢ë̸̩ị̵̽r̴̺̆d̴̴̴̘̘͎̕̕ẗ̷͕x̷̮ṱ̸̷̮̏ṱ̸̸̜̏͒ļ̵̶̱͐k̸̗̈ě̸̸͖̗̈ě̸̸͖̥̄h̸̰̔i̵̵̿̿͜͜k̸̗̈ě̸̸͖̗̈ě̸̶̶̸̸̵̴̛̛͖̤̰̔̿͜x̷̶̸̸̸̵ke̸̸̵̷h̵i̷s̴,但不应捕获EMOJIS。 ????

【问题讨论】:

  • “过滤器”是什么意思?删除这些文本,还是“规范化”?
  • @WiktorStribiżew Liley 从聊天条目中删除他们
  • 检测是否有任何 zalgo 在字符串中。例如-> const hasZalgo = zalgo.match(zalgoPattern);

标签: javascript regex string regular-language zalgo


【解决方案1】:

这里是测试方法

const re = /%CC%/g
const hasZalgo = txt => re.test(encodeURIComponent(txt));  

console.log(hasZalgo("w̵̢̃2ë̸̩́ị̵̽r̴̺̆d̴̘̕ ̴͎́ẗ̷͕́e̷̳̅x̷̮́ṱ̸̏ ̸̜͒ḻ̵̎i̶̧͐k̸̗̈ě̸͖ ̸̥̄t̶̛̤h̸̰̔i̵̿͜ş̴̛ 222 ?"))
console.log(hasZalgo("Weird text like %CC% this ?"))

这里是如何转换

console.log(
  decodeURIComponent(
    encodeURIComponent("w̵̢̃2ë̸̩́ị̵̽r̴̺̆d̴̘̕ ̴͎́ẗ̷͕́e̷̳̅x̷̮́ṱ̸̏ ̸̜͒ḻ̵̎i̶̧͐k̸̗̈ě̸͖ ̸̥̄t̶̛̤h̸̰̔i̵̿͜ş̴̛ 222 ?")
    .replace(/%CC(%[A-Z0-9]{2})+%20/g," ") // replace space
    .replace(/%CC(%[A-Z0-9]{2})+(\w)/g,"$2") // replace anything else
  )
)

【讨论】: