Does anyone know how to make a bad word filter that is case insinsitive? I have been google-ing all night and found some different examples of word filters (some better than others), but none that are case insensitive without changing the case of the text. I basically want to do what this forum does without having to add diferent cases to the words. Like lets say crap is a bad word, I want it to find Crap, crAP, CRAP, etc, but not crape. I know it can be done with regular expressions (which I think this board uses) but I don't know regular expressions worth crap. Here is the code I have now, but it is case sensative:
VB Code:
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         Dim xmlDocPath As String = Server.MapPath("bad_words.xml")
  3.         Dim xmlReader As XmlTextReader = New XmlTextReader(xmlDocPath)
  4.         While (xmlReader.Read())
  5.             If xmlReader.NodeType = XmlNodeType.Text Then
  6.                 alWordList.Add(xmlReader.Value)
  7.                 Trace.Write("Added: " & xmlReader.Value)
  8.             End If
  9.         End While
  10.         xmlReader.Close()
  11.     End Sub
  12.  
  13.     Public Function CheckString(ByVal InputString As String) As String
  14.         Dim r As Regex
  15.         Dim element As String
  16.         Dim output As String
  17.         Trace.Write("Checking " & InputString)
  18.         For Each element In alWordList
  19.             r = New Regex("\b" & element)
  20.             Trace.Write("Checking: " & element)
  21.             InputString = r.Replace(InputString, "****")
  22.         Next
  23.         Trace.Write("Returning " & InputString)
  24.         Return InputString
  25.     End Function
  26.  
  27.  
  28. XML
  29. <words>
  30.     <word>badword</word>
  31.     <word>reallybadword</word>
  32.     <word>omgyouusedthisword</word>
  33. </words>