Regex in if statement.

Terry Reedy tjreedy at udel.edu
Sun Mar 20 21:12:15 EDT 2011


On 3/20/2011 8:46 PM, Ken D'Ambrosio wrote:
> Hey, all -- I know how to match and return stuff from a regex, but I'd
> like to do an if, something like (from Perl, sorry):
>
> if (/MatchTextHere/){DoSomething();}
>
> How do I accomplish this in Python?

Look at the doc to see what are the possible return values from the 
function you want to use and which indicates failure. Then test that the 
result is not the failure value.

-- 
Terry Jan Reedy




More information about the Python-list mailing list