Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.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正则表达式也匹配特殊字符_Python_Regex - Fatal编程技术网

python正则表达式也匹配特殊字符

python正则表达式也匹配特殊字符,python,regex,Python,Regex,目前我使用这个简单的脚本来搜索字符串中的标记 tag = "#tag" text = "test string with #tag inserted" match = re.search(tag, text, re.IGNORECASE) #matches 现在假设文本包含一个a-acute tag = "#tag" text = "test string with #tág inserted" match = re.search(tag, text, re.IGNORECASE) #does

目前我使用这个简单的脚本来搜索字符串中的标记

tag = "#tag"
text = "test string with #tag inserted"
match = re.search(tag, text, re.IGNORECASE) #matches
现在假设文本包含一个a-acute

tag = "#tag"
text = "test string with #tág inserted"
match = re.search(tag, text, re.IGNORECASE) #does not match :(
我如何使这场比赛有效?应该也适用于其他特殊角色(è、è、è等)


提前谢谢

您可以使用以下方法规范化文本:

out:

['#tag', '#tag']

unidecode
不是标准的Python库。你能发布一个链接吗?这并不能说明
'tag'
本身可能在字符串中。@Volatility--我不确定我是否明白,你能详细说明一下吗。嗯,现在我已经读过这个问题了。。。我以为OP想要找到所有的
“#tág”
s,而不是
“#tag”
——很明显我看错了,对不起;)“其他特殊角色”是否包括以下内容∆ 或Ж或新 ?
['#tag', '#tag']