我想用一个友好的unicode版本替换下面的正则表达式,该版本可以抓取像http://➡.ws和其他非ascii IRIs的东西。其目的是从用户的文本中抓取这些文本,并将其编码并将其html化为真正的链接。蟒蛇unicode正则表达式
Python提供了一个re.UNICODE标志,它改变了\ w的含义,但是在这种情况下(我可以看到)这不是超级有用,因为它被定义为“字母数字字符和下划线”,而不是全部字符类包括下划线。
domain_regex = re.compile(r"""
(
(https?://)
(
[0-9a-zA-Z]
[0-9a-zA-Z_-]*
\.
)+
[a-zA-Z]{2,4}
)
| # begins with an http scheme followed by a domain, or
(
(?<! # negative look-behind
[[email protected]]
)
(
[0-9a-zA-Z]
[0-9a-zA-Z_-]*
\.
)+
# top-level domain names
com|ca|net|org|edu|gov|biz|info|mobi|name|
us|uk|fr|au|be|ch|de|es|eu|it|tv|cn|jp
)
""", re.VERBOSE)
更多非ASCII域名:
- Bücher.ch - (。瑞士 - 德国 “书”,目前下)
-
- http://실례.테스트
这是http://stackoverflow.com/questions/1832893/python-regex-matching-unicode-properties的可能重复如果您需要更多帮助,请告知我们 – buckley 2012-03-22 22:08:50