单一关键词整句匹配及关键词替换的解决方案
过滤方法:
response.write ReP("需要过滤的内容",1)
'关键词过滤,types=1整句过滤;types=2关键词替换
Function ReP(Str,types)
StrBadWords="美沙酮|美沙酮|麦司卡林|麦角酸二乙基酰胺|吗啡|可卡因|咖啡因|海洛因"
arrayList=split(StrBadWords,"|")
set re=New RegExp
For i=0 To Ubound(arrayList)
If types=1 Then
keywords=Trim(arrayList(i))
re.Pattern = "[,,.。!!]*[^,,.。!!]*"&keywords&"[^,,.。!!]*[,,.。!!]*"
re.IgnoreCase = True
're.Global = True
Str=re.replace(Str,"。")'替换为一个自己想设的语句结束符号
Else
Str=Replace(Str, ""&arrayList(i)&"", "××")
End If
Next
Set re=Nothing
ReP=Str
End Function
response.write ReP("需要过滤的内容",1)
'关键词过滤,types=1整句过滤;types=2关键词替换
Function ReP(Str,types)
StrBadWords="美沙酮|美沙酮|麦司卡林|麦角酸二乙基酰胺|吗啡|可卡因|咖啡因|海洛因"
arrayList=split(StrBadWords,"|")
set re=New RegExp
For i=0 To Ubound(arrayList)
If types=1 Then
keywords=Trim(arrayList(i))
re.Pattern = "[,,.。!!]*[^,,.。!!]*"&keywords&"[^,,.。!!]*[,,.。!!]*"
re.IgnoreCase = True
're.Global = True
Str=re.replace(Str,"。")'替换为一个自己想设的语句结束符号
Else
Str=Replace(Str, ""&arrayList(i)&"", "××")
End If
Next
Set re=Nothing
ReP=Str
End Function