擅长:python、mysql、java
<p>使用<a href="https://docs.python.org/2/library/unicodedata.html#unicodedata.normalize" rel="nofollow noreferrer">unicodedata.normalize</a>:</p>
<pre><code>accented_string = u"Málaga"
unicodedata.normalize( "NFKD", accented_string ).encode( "ascii", "ignore" )
</code></pre>
<p>您可以使用4种规范化形式:“NFC”、“NFKC”、“NFD”和“NFKD”。在</p>
<p>下面是在上面链接的文档中使用它的详细信息:</p>
<p>Unicode标准基于规范等价和兼容性等价的定义,定义了Unicode字符串的各种规范化形式。在Unicode中,几个字符可以用不同的方式表示。例如,字符U+00C7(带加符的拉丁文大写字母C)也可以表示为序列U+0043(拉丁文大写字母C)U+0327(组合加符)。在</p>
<p>对于每个字符,有两种范式:范式C和范式D。范式D(NFD)也被称为正则分解,它将每个字符转换成其分解形式。标准格式C(NFC)首先应用规范分解,然后再次组合预组合字符。在</p>
<p>除了这两种形式之外,还有两种基于相容性等价性的额外规范形式。在Unicode中,支持某些通常与其他字符统一的字符。例如,U+2160(罗马数字一)与U+0049(拉丁文大写字母I)实际上是一回事。但是,为了与现有字符集(例如gb2312)兼容,Unicode支持它。在</p>
<p>标准格式KD(NFKD)将应用兼容性分解,即用它们的等价物替换所有兼容字符。范式KC(NFKC)首先应用相容性分解,然后应用正则组合。在</p>
<p>即使两个unicode字符串被规范化,在人类读者看来是一样的,如果一个有组合字符,而另一个没有,它们可能无法进行相等的比较。在</p>