从重音字符中删除重音 [英] Remove accents from accented characters

查看:56
本文介绍了从重音字符中删除重音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求建议,我应该使用什么库和/或函数将国际文本转换为英文字符.

I am looking for advice what library and/or function should I use to convert international text to it's English characters alternative.

例如

Vous avez aimé l'épée offerte par les elfes à Frodon 

转换成

Vous avez aime l'epee offerte par les elfes a Frodon 

推荐答案

首先你可以使用 分解字符Unicode::Normalize,那么你可以使用一个简单的正则表达式来删除所有的变音符号.(我认为只需抓取所有非空格标记字符就可以了,但可能有一两个不明显的例外.)

First you can decompose the characters using Unicode::Normalize, then you can use a simple regex to delete all the diacriticals. (I think simply grabbing all the non-spacing mark characters should do it, but there might be an obscure exception or two.)

这是一个例子:

use strict;
use warnings;
use utf8;

use Unicode::Normalize;

my $test = "Vous avez aimé l'épée offerte par les elfes à Frodon";

my $decomposed = NFKD( $test );
$decomposed =~ s/\p{NonspacingMark}//g;

print $decomposed;

输出:

Vous avez aime l'epee offerte par les elfes a Frodon

这篇关于从重音字符中删除重音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆