Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python正则表达式';s模糊搜索不';使用or运算符时,不要返回所有匹配项_Python_Regex_Fuzzy Search - Fatal编程技术网

Python正则表达式';s模糊搜索不';使用or运算符时,不要返回所有匹配项

Python正则表达式';s模糊搜索不';使用or运算符时,不要返回所有匹配项,python,regex,fuzzy-search,Python,Regex,Fuzzy Search,例如,当我使用 regex.findall(r"(?e)(mazda2 standard){e<=1}", "mazda 2 standard") regex.findall(r"(?e)(mazda2 standard|mazda 2){e<=1}", "mazda 2 standard") regex.findall(r)(?e)(马自达2标准){e见: 默认情况下,模糊匹配将搜索满足给定约束的第一个匹配项。ENHANCEMATCH标志将使其尝试改进找到的匹配项的匹配度(即减

例如,当我使用

regex.findall(r"(?e)(mazda2 standard){e<=1}", "mazda 2 standard")
regex.findall(r"(?e)(mazda2 standard|mazda 2){e<=1}", "mazda 2 standard")
regex.findall(r)(?e)(马自达2标准){e见:

默认情况下,模糊匹配将搜索满足给定约束的第一个匹配项。
ENHANCEMATCH
标志将使其尝试改进找到的匹配项的匹配度(即减少错误数)。

BESTMATCH
标志将使其搜索最佳匹配

您可以使用您的代码获得
mazda 2
,因为此匹配不包含错误

因此,使用
BESTMATCH
标志(内联修饰符选项是
(?b)
):

导入正则表达式
>>>regex.findall(r)(?be)(马自达2标准|马自达2){你能解释一下除了“马自达2标准”之外,你希望regex匹配什么吗?我问这个问题是因为我觉得该模式的其余部分在语法上是无效的。我很惊讶它与任何东西都匹配。嗨。在后一种情况下,我想看看['mazda 2',mazda 2标准']。当我运行这些时没有语法错误,但请告诉我是否可能写了什么错误。非常感谢。啊,我的糟糕,我没有注意到您使用的是
regex
,而不是
re
。因此模式应该是正确的。对此表示抱歉。@RomanPerekhrest:我在Python 2.7.9中测试了它。regex lib版本:2016.01.10
regex.findall(r"(?e)(mazda2 standard|mazda 2){e<=1}", "mazda 2 standard", overlapped=True)
>>> import regex
>>> regex.findall(r"(?be)(mazda2 standard|mazda 2){e<=1}", "mazda 2 standard")
['mazda 2 standard']
>>>