?傳送門https://github.com/ccppluagopy/SensitiveWord-Lua
轉這個位置已經寫的很棒了,然后稍微修改一下,改用小寫來檢測,原文替換保留大寫的原文
function MsgParser:getString(s)if type(s) ~= 'string' then return endlocal i = 1local len = strLen(s)local word, idx, tmpslocal returnStr = s;s = string.lower(s);while true doword = strSub(s, i)idx = _detect(_tree, word, i)if idx thentmps = strSub(s, 1, i-1)for j=1, idx-i+1 dotmps = tmps .. _maskWordends = tmps .. strSub(s, idx+1)tmps1 = strSub(returnStr, 1, i-1)for j=1, idx-i+1 dotmps1 = tmps1 .. _maskWordendreturnStr = tmps1 .. strSub(returnStr, idx+1)i = idx+1elsei = i + 1endif i > len thenbreakendendreturn returnStr
end
這樣我們使用就已經ok了