re.search making no match == 0

Lance Hoffmeyer lance at augustmail.com
Thu Feb 15 12:05:35 EST 2007


Hey all,

I have a search:

VAR = re.search("PROVEN.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*?" , pcpT9, re.S ).group(1)  #.split()[1]

that does not match (sometimes it will and sometimes it will not match)

Traceback (most recent call last):
  File "P:\Burke\TRACKERS\Ortho-McNeil\Automation\Wave3\test.py", line 53, in ?
    VAR = re.search("PROVEN.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*?" , pcpT9, re.S ).group(1)  #.split()[1]
AttributeError: 'NoneType' object has no attribute 'group'


Is there a way in python to make this "non" match equal a value (say, "0")?

This one line is actually a series of searches

Reasons = ["EFFICACY","EFFECTIVE","WORKS QUICKLY","PROVEN","SAFETY","LITTLE","WELL","  BETTER","SAMPLES"] # Reasons(29)
VAR = [re.search(r"%s.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*?" % i, pcpT9, re.S ).group(1) for i in Reasons ]  #.split()[1]

and one of the items in the array may or may not be present.

Lance



More information about the Python-list mailing list