ADA*_*MJR 2 javascript regex string regular-language zalgo
我正在创建一个消息过滤系统,它检测 z???a???l???g???o???。
我当前的正则表达式是,/([^\u0009-\u02b7\u2000-\u20bf\u2122\u0308]|(?![^aeiouy])\u0308)/gm
但这也捕获表情符号。
正则表达式应该过滤所有 w???e???i???r???d??? ???文本??????喜欢??????这个???或 t?e?x?t? ?喜欢??t?h?i?s?,但不应捕捉表情符号。
以下是测试方法
const re = /%CC%/g
const hasZalgo = txt => re.test(encodeURIComponent(txt));
console.log(hasZalgo("w???2e???i???r???d??? ???t???e???x???t??? ???l???i???k???e??? ???t???h???i???s??? 222 "))
console.log(hasZalgo("Weird text like %CC% this "))Run Code Online (Sandbox Code Playgroud)
这是转换方法
console.log(
decodeURIComponent(
encodeURIComponent("w???2e???i???r???d??? ???t???e???x???t??? ???l???i???k???e??? ???t???h???i???s??? 222 ")
.replace(/%CC(%[A-Z0-9]{2})+%20/g," ") // replace space
.replace(/%CC(%[A-Z0-9]{2})+(\w)/g,"$2") // replace anything else
)
)Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
602 次 |
| 最近记录: |