make RE more cleaver to avoid inappropriate : sre_constants.error: redefinition of group name

aspineux aspineux at gmail.com
Thu Mar 29 11:48:14 EDT 2007


On 29 mar, 16:22, "aspineux" <aspin... at gmail.com> wrote:
> I want to parse
>
> 'foo at bare' or '<foot at bar>' and get the email address foo at bar
>
> the regex is
>
> r'<\w+@\w+>|\w+@\w+'
>
> now, if I want to give it a name
>
> r'<(?P<email>\w+@\w+)>|(?P<email>\w+@\w+)'
>
> sre_constants.error: redefinition of group name 'email' as group 2;
> was group 1
>
> BUT because I use a | , I will get only one group named 'email' !

THEN my regex is meaningful, and the error is meaningless and
somrthing
should be change into 're'

But maybe I'm wrong ?

>
> Any comment ?

I'm trying to start a discussion about something that can be improved
in 're',
not looking for a solution about email parsing :-)


>
> PS: I know the solution for this case is to use  r'(?P<lt><)?(?P<email>
> \w+@\w+)(?(lt)>)'





More information about the Python-list mailing list