python regex character group matches

Fredrik Lundh fredrik at pythonware.com
Wed Sep 17 17:15:54 CEST 2008


Steven D'Aprano wrote:

>> Assuming that you want to find runs of \uXXXX escapes, simply use
>> non-capturing parentheses:
>>
>>     pat = re.compile(u"(?:\\\u[0-9A-F]{4})")
> 
> Doesn't work for me:
> 
>>>> pat = re.compile(u"(?:\\\u[0-9A-F]{4})")

it helps if you cut and paste the right line...  here's a better version:

     pat = re.compile(r"(?:\\u[0-9A-F]{4})+")

</F>




More information about the Python-list mailing list