Forum Moderators: open

Message Too Old, No Replies

Custom dictionary for website

Need regular expression to match any word with a number in it

         

GaryK

8:08 pm on Jul 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am upgrading a custom-written dictionary for use with my ASP/SQL Server based message board.

At the user's discretion I want to avoid spell checking any words with numbers in them.

I'm pretty good with fairly simple regular expressions but I'm having trouble constructing a single pattern that will allow me to find all words that have at least one number anywhere in them so that I can remove them from the list of words that need to be spell checked.

In otherwords, the pattern should find each of the following examples: 1ABC, 99ABC, ABC1, ABC99, ABC1D, and ABC99D.

Is the above possible or will I need to use three separate patterns?

Thanks in advance for any help.

GaryK

6:53 pm on Aug 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I really need some help, folks. Does anyone know how to construct the pattern I need? Thanks.

GaryK

5:22 pm on Aug 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Isn't there someone out there who can help me with this problem, please.

TheDave

11:33 pm on Aug 6, 2003 (gmt 0)

10+ Year Member



Regular expressions are not my strong point ;) You're asking this in the ASP forums, but I'm a bit confused as to how you're actually implementing this. Anyway, I guess you could do something like:

dim input
dim input_words
dim reLetters
dim reNumbers

set reLetters = new RegExp
set reNumbers = new RegExp

reLetters.IgnoreCase = True
reLetters.Pattern = "a¦b¦c¦d¦e¦f¦g¦h¦i¦j¦k¦l¦m¦n¦o¦p¦q¦r¦s¦t¦u¦v¦w¦x¦y¦z"

reNumbers.IgnoreCase = True
reNumbers.Pattern = "1¦2¦3¦4¦5¦6¦7¦8¦9¦0"

'get your input from wherever
'input = request("input")

input = "im a little 666 tea pot sh0rt and stout"

if not input = "" then
'split the input
input_words = split(input & " ", " ")

c = 0
while c < ubound(input_words)
'perform a test on the word to see if it's got numbers in it
'up to you how you do this.

if (reNumbers.Test(input_words(c)) = true and reLetters.Test(input_words(c)) = true) then
'you have a word with letters and numbers
response.write input_words(c)
end if

c = c + 1
wend

end if

set reNumbers = nothing
set reLetters = nothing

GaryK

11:46 pm on Aug 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, Dave. Thanks for taking a stab at this. After a week of no replies at all I'm grateful for any help at all. The reason I asked my question here is because the syntax for regular expressions in ASP seems to be slightly different than what the *nix world uses. I was hoping for a slightly more elegant solution using just one pattern and the regexp replace function. But at this point my main concern is coming up with something that works and with a few mods to suit my application your suggestion does seem like it will work. Thanks.

ziggystardust

11:17 am on Aug 7, 2003 (gmt 0)

10+ Year Member



Regular expressions aren't exactly my best field either but... heck, I'll try :)

You're looking for something that will get all words containing a number from a text and remove them. Okay. Can't you use the opposite instead - return and keep all words that don't have a number in them?

^[a-zA-Z]+$

No?

//ZS

GaryK

6:01 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, ZS.

Thanks for your suggestion. I'll give it a try but the logic is totally opposite of what I'm trying to do so I'm not sure it will work.

Basically what I'm trying to do is take a message like this one, strip out HTML, URLs, and anything else that doesn't need to be spell checked (like words with numbers in them) and then spell check what I have left.