Regex Error Handling?!
Eladio Ventura
eladioventura at hotmail.com
Sun Jan 5 13:40:33 EST 2003
* Fredrik Lundh <fredrik at pythonware.com> [030105 15:39]:
> Eladio Ventura wrote:
>
> re.search returns a match object if the pattern matches, or None
> if it doesn't match. the "if" statement treats match objects as true
> values, so you can use "if" right away to check for matches:
>
> for line in lines:
> match = regex.search(line)
> if match:
> matches.append(match.group(part))
> else:
> print "We got a mismatched line!"
Thanks a lot Frederik! That's exactly what I was looking for.:0)
--
"Thinking gives you wrinkles!"
Malibu Stacy, the Simpsons
More information about the Python-list
mailing list