Python 将短语与unicode字符匹配的正则表达式

Python 将短语与unicode字符匹配的正则表达式,python,regex,unicode,Python,Regex,Unicode,我试图用Python(repackage)中的正则表达式解析以下句子中的指定范围,但到目前为止运气不佳: body = 'Adulticides are modelled by increasing the mosquito mortality rate [9] , [20] – [22] .' 我正在努力匹配 [20] – [22] 问题似乎是连字符不是通常的-,而是一些unicode连字符- 最接近于匹配此范围前半部分的是: m = re.findall(r'\[20\] ', bod

我试图用Python(
re
package)中的正则表达式解析以下句子中的指定范围,但到目前为止运气不佳:

body = 'Adulticides are modelled by increasing the mosquito mortality rate [9] , [20] – [22] .'
我正在努力匹配


[20] – [22]

问题似乎是连字符不是通常的
-
,而是一些unicode连字符
-

最接近于匹配此范围前半部分的是:

m = re.findall(r'\[20\] ', body)

如何匹配整个范围?

您需要将其与unicode标志一起使用,如下所示:

m = re.findall(r'\[\d+\] – \[\d+\]', body, re.UNICODE)

这将从您指定的字符串返回
[20]-[22]

您不能将连字符复制并粘贴到正则表达式中吗?[20] \s(–|-)\s[22]编辑:由于某种原因,我的括号转义没有显示在注释中。@Martyn是的,这是另一个选项。顺便说一句,对代码格式使用反勾号:)