Python正则表达式将字符串中的非ASCII字符转换为最接近的ascii等效字符 [英] Python regex to convert non-ascii characters in a string to closest ascii equivalents
问题描述
我正在寻找简单的Python函数,它接受一个字符串并返回一个类似的,但所有非ascii字符转换为他们最接近的ascii等价。
例如,应该删除变音符号和什么。
我想象一定有一个漂亮的规范的方式来做到这一点,有很多相关的stackoverflow问题,但我没有找到一个简单的答案,所以它似乎值得一个单独的问题。
I'm seeking simple Python function that takes a string and returns a similar one but with all non-ascii characters converted to their closest ascii equivalent. For example, diacritics and whatnot should be dropped. I'm imagining there must be a pretty canonical way to do this and there are plenty of related stackoverflow questions but I'm not finding a simple answer so it seemed worth a separate question.
示例输入/输出:
"Étienne" -> "Etienne"
推荐答案
阅读这个问题,东西更好。
Reading this question made me go looking for something better.
https:// pypi。 python.org/pypi/Unidecode/0.04.1
完全符合您的要求。
这篇关于Python正则表达式将字符串中的非ASCII字符转换为最接近的ascii等效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!