我已经在Stackoverflow上阅读了其他问题,但仍然无法解决。如果这个问题已经有答案了,我很抱歉,但是我没有找到任何可以解决我的问题的内容。
>>> import re
>>> m = re.match(r'^/by_tag/(?P<tag>\w+)/(?P<filename>(\w|[.,!#%{}()@])+)$', '/by_tag/xmas/xmas1.jpg')
>>> print m.groupdict()
{'tag': 'xmas', 'filename': 'xmas1.jpg'}
一切都很好,然后我尝试一些带有挪威字符(或更多类似于Unicode的内容)的东西:
>>> m = re.match(r'^/by_tag/(?P<tag>\w+)/(?P<filename>(\w|[.,!#%{}()@])+)$', '/by_tag/påske/øyfjell.jpg')
>>> print m.groupdict()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'groupdict'
我该如何匹配像øæå这样的典型 Unicode 字符?我希望能够在上面的标签组和文件名的标签组中匹配这些字符。