newbie re question

Inyeol Lee inyeol.lee at siimage.com
Wed Nov 6 16:03:31 EST 2002


In the first match ('', 'aadf', ' '), you already consumed whitespace, so the RE
engine starts looking from "cdase ..." for next match, and there's no leading space and
it's not a string start, so "cdase ..." doesn't match.

Inyeol...

On Wed, Nov 06, 2002 at 07:58:47PM +0000, Gonçalo Rodrigues wrote:
> Hi,
> 
> I've been trying to grok re's and settled myself a little exercise:
> concoct a re for a Python identifier. 
> 
> Now what I got is
> 
> >>> pattern = re.compile(r'(\s|^)([\w_][\w\._]*)(\s|$)')
> >>> pattern.findall('aadf cdase b ad:aa aasa a.aa a@ aa _aa _aafr@ aa_aa aa__a?jk')
> [('', 'aadf', ' '), (' ', 'b', ' '), (' ', 'aasa', ' '), (' ', 'aa', '
> '), (' ', 'aa_aa', ' ')]
> 
> But as you can see from the results, not all valid identifiers get
> caught. For example, why isn't 'cdase' caught? Or 'a.aa'? Can someone
> enlighten me on what I am doing wrong (or what I am not doing right)?
> 
> TIA,
> G. Rodrigues
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list