正则表达式来检测扎尔戈



我正在创建一个消息过滤系统,用于检测 zێۣۗḁ̵̑l̉̃ۦg̐̓̒oۓ̕ۥ。

我目前的正则表达式是/([^u0009-u02b7u2000-u20bfu2122u0308]|(?![^aeiouy])u0308)/gm但这也捕获了表情符号。

正则表达式应过滤所有 w̵̤̃ë̸̩́ị̵̽r̴̼̼̅d̴̘̕ ̴ێ́ẗ̷ە́e̷̅x̷̮́ṱ̸̏ ̸̜ےḻ̵̎ȋ̶̧k̸̗̈ě̸ۖ ̸̥̄t̶̛̤h̰̰̃i̵̿ۜş̴̛ 或 t̶e̶x̴t̸ ̸l̵i̶k̷e̸ ̵t̷h̵i̷s̴,但不应捕获表情符号。

以下是测试方法

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

这是转换的方法

console.log(
decodeURIComponent(
encodeURIComponent("w̵̢̃ë̸̩́ị̵̽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
)
)

最新更新