Matching C integer constants with re

Just just at
Thu Jun 12 10:49:17 CEST 2003

In article <1xxzofj8.fsf at>,
 Thomas Heller <theller at> wrote:

> I'm trying to match C integer constants with the re module, but cannot
> get it to work correctly.
> This is the pattern I use:
>  re.compile(r"(0[xX][0-9a-fA-F]+|\d+)([uU]|[lL]|[uU][lL]|[lL][uU])?")
> and it fails to match constants with a two character suffix like
> these: "123ul" and "123lu", although "123u" and "123l" are found correctly.
> Can anyone see what's wrong?

I'm by no means a regex expert, but I think you have to match the longer 
ones first:


This seems to fix your script for me.


More information about the Python-list mailing list