Matching zero only once using RE

Jaime Wyant programmer.py at gmail.com
Fri Oct 7 13:52:58 EDT 2005


On 7 Oct 2005 10:35:22 -0700, GregM <gregm at taming-tech.com> wrote:
> 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
>
Shouldn't your regular expression be "You have found 0 matches".  If
you're looking for that exact string, then you should use that.

This works for me:

>>> s = "asdfasfdfs You have found 0 matches asdfasdfasdf"
>>> import re
>>> re.search("You have found 0 matches", s)
  <_sre.SRE_Match object at 0x00B21800>

ALso, it looks like your pattern is off.  The pattern you use is given below...

SecondarySearchTerm = 'You found (0){1} matches'

However, you state that you are looking for 'You have found 0 matches'

* Notice the 'have' in the string you are searching for and it's
absence in your search term ;)

HTH,
jw



More information about the Python-list mailing list