Doing both regex match and assignment within a If loop?
arnodel at gmail.com
Fri Mar 29 11:41:26 CET 2013
On Friday, 29 March 2013, Alain Ketterlin wrote:
> > expression1 = re.compile(r'....')
> > expression2 = re.compile(r'....')
> Just a quick remark: regular expressions are pretty powerful at
> representing alternatives. You could just stick everything inside a
> single re, as in '...|...'
Then use the returned match to check which alternative was recognized
> (make sure you have at least one group in each alternative).
Yes, and for extra ease/clarity you can name these alternatives (
'(?P<name>pattern)'). Then you can do
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list