newbie re question

Gonçalo Rodrigues op73418 at mail.telepac.pt
Wed Nov 6 14:58:47 EST 2002


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



More information about the Python-list mailing list