【发布时间】:2019-05-18 16:38:22
【问题描述】:
我想找到两个至少有一个错误的相似字符串。 我想使用re库中内置的python。
例子
import re
re.match(r"anoother","another") #this is None indeed
它应该返回 True 并检查它是否有一个或两个拼写错误。
我已经寻找了很长的重新文档 但是我不知道当有一种类型时如何使用这些知识
a="this is the anoother line\n"
b="this is the another line\n"
c=re.search(r"{}".format(a),b) #how to write regex code here?
#c =True #it should return True
我希望返回True
re.any_regex_func(r"anyregex this is anoother line anyregex","this is another line")
如果它有多个类型,则返回 false
【问题讨论】:
-
我不认为正则表达式是正确的工具。您可以尝试查看确定编辑距离的算法。
-
Google 类似“python 模糊字符串匹配”之类的东西,正则表达式可能不是您要找的。span>
-
在标准库中有用于此类任务的“difflib”模块。
-
好的。我是正则表达式的新手,这就是为什么我问它是否可能。我可以在没有正则表达式的情况下编写算法。
-
谢谢大家!我将搜索另一个库
标签: python regex regex-lookarounds regex-group regex-greedy