Matching zero only once using RE

GregM gregm at taming-tech.com
Fri Oct 7 13:35:22 EDT 2005


Hi,

I've looked at a lot of pages on the net and still can't seem to nail
this. Would someone more knowledgeable in regular expressions please
provide some help to point out what I'm doing wrong?

I am trying to see if a web page contains the exact text:
You have found 0 matches

But instead I seem to be matching all sorts of expected line like
You have found <a number up to 5 digits long with comma> matches
for example:
You have found 34 matches
You have found 189 matches
You have found 16,734 matches
You have found 1,706 matches
You have found 300 matches

The last 2 I thought I had eliminated but sadly it seems not the
examples above actually seem to match my expression below. :(

Here is what I'm doing:
zeromatch = []
SecondarySearchTerm = 'You found (0){1} matches'
primarySearchTerm = 'Looking for Something'
primarySearchTerm2 = 'has been an error connecting'

# pagetext is all the body text on a web page.
# I'm using COM to drive MSIE and pagetext =  doc.body.outerText

if (re.search(primarySearchTerm, pagetext)  or
re.search(primarySearchTerm2, pagetext)):
   failedlinks.append(link)
elif (re.search(SecondarySearchTerm, pagetext)):
   zeromatch.append(link)

I've tried other RE's be had even more spectacular failures any help
would be greatly appreciated.

Thanks in Advance,
Greg Moore
Software Test
Shop.com




More information about the Python-list mailing list