re.Scanner - match python dot notation

MRAB python at mrabarnett.plus.com
Mon Feb 7 11:47:11 EST 2011


On 07/02/2011 15:34, Christian K. wrote:
> Hi,
>
> I am trying to find a regexp to be used with re.Scanner that matches the
> 'package.module.member' syntax. More specifically I want to parse
> function strings like
>
> numpy.sin(x*a+w)
>
> and sort out variables/constants.
>
> This one here works using re.match but fails when used with Scanner (due
> to the grouping () I guess).
>
> r'((?=.*[a-zA-Z])(?=.+[\.]).+)[\(\+\-]+'
>
> I highly appreciate your comments.
>
> Regards, christian
>
I'm not sure about your regex, but I'd probably use this:

     r'[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*'



More information about the Python-list mailing list