Re: Using re module better

2008-03-05 Thread Steven D'Aprano
On Wed, 05 Mar 2008 11:09:28 -0800, castironpi wrote: > On another note, why do people X, Y, and Z, including me, all hate to > write a= b(); if a: a.something()? Is this a guessing game? You want us to guess why YOU hate to do something? Okay, I'm game for guessing games... You were traumatiz

Re: Using re module better

2008-03-05 Thread castironpi
On Mar 5, 6:12 am, Tim Chase <[EMAIL PROTECTED]> wrote: > > if (match = re.search('(\w+)\s*(\w+)', foo)): > > Caveat #1:  use a raw string here > Caveat #2:  inline assignment is verboten > >    match = re.search(r'(\w+)\s*(\w*+)', foo) >    if match: > > >     field1 = match.group(1) > >     field

Re: Using re module better

2008-03-05 Thread Bruno Desthuilliers
Mike a écrit : > I seem to fall into this trap (maybe my Perl background) where I want > to simultaneously test a regular expression and then extract its match > groups in the same action. > For instance: > > if (match = re.search('(\w+)\s*(\w+)', foo)): > field1 = match.group(1) > field2

Re: Using re module better

2008-03-05 Thread Tim Chase
> if (match = re.search('(\w+)\s*(\w+)', foo)): Caveat #1: use a raw string here Caveat #2: inline assignment is verboten match = re.search(r'(\w+)\s*(\w*+)', foo) if match: > field1 = match.group(1) > field2 = match.group(2) This should then work more or less. However, since y

Using re module better

2008-03-05 Thread Mike
I seem to fall into this trap (maybe my Perl background) where I want to simultaneously test a regular expression and then extract its match groups in the same action. For instance: if (match = re.search('(\w+)\s*(\w+)', foo)): field1 = match.group(1) field2 = match.group(2) ... (com