Forum Moderators: open

Message Too Old, No Replies

Finding Words in the middle of URL Strings

         

traeanthony

3:07 am on Jun 26, 2006 (gmt 0)

10+ Year Member



Let me tell you what I'm doing first. I'm making an email form and have gotten a significant amount of spam, even with the form. Most of the spam contains the same text (which I've delt with already, thanks to the help of the members of this forum) but the rest contains similar words, only in different orders.

What I would like to do is to have my asp script find those like words inside the message text box and flag it as spam (I already have the flagging part done) All I need is to figure out how to find those words when they are randomly placed through out the message (I hope that makes sence.)

I know this usually isn't the best way to prevent spam, but I figure it will help me to sort it all out.

Thanks for any help anyone may have!

-Trae

wardbekker

7:02 am on Jun 26, 2006 (gmt 0)

10+ Year Member



Hi Trae,

For searching patterns in pieces of text the RegExp object is used in vbscript. Below some example script where we search for the word "forbidden"

<%
StringToSearch = "this is the text that needs to be searched and contains the forbidden word"

Set RegularExpressionObject = New RegExp

With RegularExpressionObject
.Pattern = "forbidden"
.IgnoreCase = False
.Global = True
End With

Set expressionmatch = RegularExpressionObject.Execute(StringToSearch)

If expressionmatch.Count > 0 Then
For Each expressionmatched in expressionmatch
Response.Write "<B>" & expressionmatched.Value & "</B> was matched at position <B>" & expressionmatched.FirstIndex & "</B><BR>"
Next

Else
Response.Write "<B>" & RegularExpressionObject.Pattern & "</B> was not found in the string: <B>" & StringToSearch & "</B>."
End If

Set RegularExpressionObject = nothing
%>

traeanthony

1:49 pm on Jun 26, 2006 (gmt 0)

10+ Year Member



AWSOME! It worked perfectly, now let me ask this, if I wanted it to search for more than one word such as "contains" and "searched" and "forbidden", as used in your example "this is the text that needs to be searched and contains the forbidden word", how would I do that?

wardbekker

2:08 pm on Jun 26, 2006 (gmt 0)

10+ Year Member



I believe the following pattern should do that:

contains¦searched¦forbidden

wardbekker

2:10 pm on Jun 26, 2006 (gmt 0)

10+ Year Member



whoops...that should be the pipe symbol (ASCII 124)

traeanthony

2:48 pm on Jun 26, 2006 (gmt 0)

10+ Year Member



Thank you so much for all your help! Everything works exactly how I need it to!