这是我的正则表达式:
(?P=<streetname>[a-zæøå ]+)(?:[ ]+)(?P=<housenumber>\d+)(?:[ ]+),(?:[ ]+)(?P=<postalcode>\d{1,4})(?:[ ]+)(?P=<city>[a-zæøå ]+)
所有组名仅包含 ASCII 字符,为什么会出错?
回溯(最近一次通话最后):
文件“addrtools.py”,第 46 行,在
主要的()
文件“addrtools.py”,第 43 行,在 main
extract_address('Testaddress 15B, 1234 奥斯陆')
文件“addrtools.py”,第 35 行,在 extract_address
匹配=重新匹配(pat_full,字符串)
匹配中的文件“/Users/tomas/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/re.py”,第 137 行
return _compile(模式,标志).match(字符串)
_compile 中的文件“/Users/tomas/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/re.py”,第 242 行
raise error, v # 无效表达式
sre_constants.error:组名中的错误字符
我已经确认pat_full确实包含上述正则表达式。此外,我的文档以 UTF-8 编码并设置为 UTF-8 模式 ( # --*-- Encoding: UTF-8 --*--)。