regular - reemplazar todos los caracteres de una cadena javascript
Eliminar acentos/diacríticos en una cadena en JavaScript (28)
Aquí hay un script muy rápido basado en el estándar Unicode, tomado de aquí: http://semplicewebsites.com/removing-accents-javascript
var Latinise={};Latinise.latin_map={"Á":"A","Ă":"A","Ắ":"A","Ặ":"A","Ằ":"A","Ẳ":"A","Ẵ":"A","Ǎ":"A","Â":"A","Ấ":"A","Ậ":"A","Ầ":"A","Ẩ":"A","Ẫ":"A","Ä":"A","Ǟ":"A","Ȧ":"A","Ǡ":"A","Ạ":"A","Ȁ":"A","À":"A","Ả":"A","Ȃ":"A","Ā":"A","Ą":"A","Å":"A","Ǻ":"A","Ḁ":"A","Ⱥ":"A","Ã":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ḃ":"B","Ḅ":"B","Ɓ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ć":"C","Č":"C","Ç":"C","Ḉ":"C","Ĉ":"C","Ċ":"C","Ƈ":"C","Ȼ":"C","Ď":"D","Ḑ":"D","Ḓ":"D","Ḋ":"D","Ḍ":"D","Ɗ":"D","Ḏ":"D","Dz":"D","Dž":"D","Đ":"D","Ƌ":"D","DZ":"DZ","DŽ":"DZ","É":"E","Ĕ":"E","Ě":"E","Ȩ":"E","Ḝ":"E","Ê":"E","Ế":"E","Ệ":"E","Ề":"E","Ể":"E","Ễ":"E","Ḙ":"E","Ë":"E","Ė":"E","Ẹ":"E","Ȅ":"E","È":"E","Ẻ":"E","Ȇ":"E","Ē":"E","Ḗ":"E","Ḕ":"E","Ę":"E","Ɇ":"E","Ẽ":"E","Ḛ":"E","Ꝫ":"ET","Ḟ":"F","Ƒ":"F","Ǵ":"G","Ğ":"G","Ǧ":"G","Ģ":"G","Ĝ":"G","Ġ":"G","Ɠ":"G","Ḡ":"G","Ǥ":"G","Ḫ":"H","Ȟ":"H","Ḩ":"H","Ĥ":"H","Ⱨ":"H","Ḧ":"H","Ḣ":"H","Ḥ":"H","Ħ":"H","Í":"I","Ĭ":"I","Ǐ":"I","Î":"I","Ï":"I","Ḯ":"I","İ":"I","Ị":"I","Ȉ":"I","Ì":"I","Ỉ":"I","Ȋ":"I","Ī":"I","Į":"I","Ɨ":"I","Ĩ":"I","Ḭ":"I","Ꝺ":"D","Ꝼ":"F","Ᵹ":"G","Ꞃ":"R","Ꞅ":"S","Ꞇ":"T","Ꝭ":"IS","Ĵ":"J","Ɉ":"J","Ḱ":"K","Ǩ":"K","Ķ":"K","Ⱪ":"K","Ꝃ":"K","Ḳ":"K","Ƙ":"K","Ḵ":"K","Ꝁ":"K","Ꝅ":"K","Ĺ":"L","Ƚ":"L","Ľ":"L","Ļ":"L","Ḽ":"L","Ḷ":"L","Ḹ":"L","Ⱡ":"L","Ꝉ":"L","Ḻ":"L","Ŀ":"L","Ɫ":"L","Lj":"L","Ł":"L","LJ":"LJ","Ḿ":"M","Ṁ":"M","Ṃ":"M","Ɱ":"M","Ń":"N","Ň":"N","Ņ":"N","Ṋ":"N","Ṅ":"N","Ṇ":"N","Ǹ":"N","Ɲ":"N","Ṉ":"N","Ƞ":"N","Nj":"N","Ñ":"N","NJ":"NJ","Ó":"O","Ŏ":"O","Ǒ":"O","Ô":"O","Ố":"O","Ộ":"O","Ồ":"O","Ổ":"O","Ỗ":"O","Ö":"O","Ȫ":"O","Ȯ":"O","Ȱ":"O","Ọ":"O","Ő":"O","Ȍ":"O","Ò":"O","Ỏ":"O","Ơ":"O","Ớ":"O","Ợ":"O","Ờ":"O","Ở":"O","Ỡ":"O","Ȏ":"O","Ꝋ":"O","Ꝍ":"O","Ō":"O","Ṓ":"O","Ṑ":"O","Ɵ":"O","Ǫ":"O","Ǭ":"O","Ø":"O","Ǿ":"O","Õ":"O","Ṍ":"O","Ṏ":"O","Ȭ":"O","Ƣ":"OI","Ꝏ":"OO","Ɛ":"E","Ɔ":"O","Ȣ":"OU","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":"A","ᴁ":"AE","ʙ":"B","ᴃ":"B","ᴄ":"C","ᴅ":"D","ᴇ":"E","ꜰ":"F","ɢ":"G","ʛ":"G","ʜ":"H","ɪ":"I","ʁ":"R","ᴊ":"J","ᴋ":"K","ʟ":"L","ᴌ":"L","ᴍ":"M","ɴ":"N","ᴏ":"O","ɶ":"OE","ᴐ":"O","ᴕ":"OU","ᴘ":"P","ʀ":"R","ᴎ":"N","ᴙ":"R","ꜱ":"S","ᴛ":"T","ⱻ":"E","ᴚ":"R","ᴜ":"U","ᴠ":"V","ᴡ":"W","ʏ":"Y","ᴢ":"Z","á":"a","ă":"a","ắ":"a","ặ":"a","ằ":"a","ẳ":"a","ẵ":"a","ǎ":"a","â":"a","ấ":"a","ậ":"a","ầ":"a","ẩ":"a","ẫ":"a","ä":"a","ǟ":"a","ȧ":"a","ǡ":"a","ạ":"a","ȁ":"a","à":"a","ả":"a","ȃ":"a","ā":"a","ą":"a","ᶏ":"a","ẚ":"a","å":"a","ǻ":"a","ḁ":"a","ⱥ":"a","ã":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ḃ":"b","ḅ":"b","ɓ":"b","ḇ":"b","ᵬ":"b","ᶀ":"b","ƀ":"b","ƃ":"b","ɵ":"o","ć":"c","č":"c","ç":"c","ḉ":"c","ĉ":"c","ɕ":"c","ċ":"c","ƈ":"c","ȼ":"c","ď":"d","ḑ":"d","ḓ":"d","ȡ":"d","ḋ":"d","ḍ":"d","ɗ":"d","ᶑ":"d","ḏ":"d","ᵭ":"d","ᶁ":"d","đ":"d","ɖ":"d","ƌ":"d","ı":"i","ȷ":"j","ɟ":"j","ʄ":"j","dz":"dz","dž":"dz","é":"e","ĕ":"e","ě":"e","ȩ":"e","ḝ":"e","ê":"e","ế":"e","ệ":"e","ề":"e","ể":"e","ễ":"e","ḙ":"e","ë":"e","ė":"e","ẹ":"e","ȅ":"e","è":"e","ẻ":"e","ȇ":"e","ē":"e","ḗ":"e","ḕ":"e","ⱸ":"e","ę":"e","ᶒ":"e","ɇ":"e","ẽ":"e","ḛ":"e","ꝫ":"et","ḟ":"f","ƒ":"f","ᵮ":"f","ᶂ":"f","ǵ":"g","ğ":"g","ǧ":"g","ģ":"g","ĝ":"g","ġ":"g","ɠ":"g","ḡ":"g","ᶃ":"g","ǥ":"g","ḫ":"h","ȟ":"h","ḩ":"h","ĥ":"h","ⱨ":"h","ḧ":"h","ḣ":"h","ḥ":"h","ɦ":"h","ẖ":"h","ħ":"h","ƕ":"hv","í":"i","ĭ":"i","ǐ":"i","î":"i","ï":"i","ḯ":"i","ị":"i","ȉ":"i","ì":"i","ỉ":"i","ȋ":"i","ī":"i","į":"i","ᶖ":"i","ɨ":"i","ĩ":"i","ḭ":"i","ꝺ":"d","ꝼ":"f","ᵹ":"g","ꞃ":"r","ꞅ":"s","ꞇ":"t","ꝭ":"is","ǰ":"j","ĵ":"j","ʝ":"j","ɉ":"j","ḱ":"k","ǩ":"k","ķ":"k","ⱪ":"k","ꝃ":"k","ḳ":"k","ƙ":"k","ḵ":"k","ᶄ":"k","ꝁ":"k","ꝅ":"k","ĺ":"l","ƚ":"l","ɬ":"l","ľ":"l","ļ":"l","ḽ":"l","ȴ":"l","ḷ":"l","ḹ":"l","ⱡ":"l","ꝉ":"l","ḻ":"l","ŀ":"l","ɫ":"l","ᶅ":"l","ɭ":"l","ł":"l","lj":"lj","ſ":"s","ẜ":"s","ẛ":"s","ẝ":"s","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ᵯ":"m","ᶆ":"m","ń":"n","ň":"n","ņ":"n","ṋ":"n","ȵ":"n","ṅ":"n","ṇ":"n","ǹ":"n","ɲ":"n","ṉ":"n","ƞ":"n","ᵰ":"n","ᶇ":"n","ɳ":"n","ñ":"n","nj":"nj","ó":"o","ŏ":"o","ǒ":"o","ô":"o","ố":"o","ộ":"o","ồ":"o","ổ":"o","ỗ":"o","ö":"o","ȫ":"o","ȯ":"o","ȱ":"o","ọ":"o","ő":"o","ȍ":"o","ò":"o","ỏ":"o","ơ":"o","ớ":"o","ợ":"o","ờ":"o","ở":"o","ỡ":"o","ȏ":"o","ꝋ":"o","ꝍ":"o","ⱺ":"o","ō":"o","ṓ":"o","ṑ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","õ":"o","ṍ":"o","ṏ":"o","ȭ":"o","ƣ":"oi","ꝏ":"oo","ɛ":"e","ᶓ":"e","ɔ":"o","ᶗ":"o","ȣ":"ou","ṕ":"p","ṗ":"p","ꝓ":"p","ƥ":"p","ᵱ":"p","ᶈ":"p","ꝕ":"p","ᵽ":"p","ꝑ":"p","ꝙ":"q","ʠ":"q","ɋ":"q","ꝗ":"q","ŕ":"r","ř":"r","ŗ":"r","ṙ":"r","ṛ":"r","ṝ":"r","ȑ":"r","ɾ":"r","ᵳ":"r","ȓ":"r","ṟ":"r","ɼ":"r","ᵲ":"r","ᶉ":"r","ɍ":"r","ɽ":"r","ↄ":"c","ꜿ":"c","ɘ":"e","ɿ":"r","ś":"s","ṥ":"s","š":"s","ṧ":"s","ş":"s","ŝ":"s","ș":"s","ṡ":"s","ṣ":"s","ṩ":"s","ʂ":"s","ᵴ":"s","ᶊ":"s","ȿ":"s","ɡ":"g","ᴑ":"o","ᴓ":"o","ᴝ":"u","ť":"t","ţ":"t","ṱ":"t","ț":"t","ȶ":"t","ẗ":"t","ⱦ":"t","ṫ":"t","ṭ":"t","ƭ":"t","ṯ":"t","ᵵ":"t","ƫ":"t","ʈ":"t","ŧ":"t","ᵺ":"th","ɐ":"a","ᴂ":"ae","ǝ":"e","ᵷ":"g","ɥ":"h","ʮ":"h","ʯ":"h","ᴉ":"i","ʞ":"k","ꞁ":"l","ɯ":"m","ɰ":"m","ᴔ":"oe","ɹ":"r","ɻ":"r","ɺ":"r","ⱹ":"r","ʇ":"t","ʌ":"v","ʍ":"w","ʎ":"y","ꜩ":"tz","ú":"u","ŭ":"u","ǔ":"u","û":"u","ṷ":"u","ü":"u","ǘ":"u","ǚ":"u","ǜ":"u","ǖ":"u","ṳ":"u","ụ":"u","ű":"u","ȕ":"u","ù":"u","ủ":"u","ư":"u","ứ":"u","ự":"u","ừ":"u","ử":"u","ữ":"u","ȗ":"u","ū":"u","ṻ":"u","ų":"u","ᶙ":"u","ů":"u","ũ":"u","ṹ":"u","ṵ":"u","ᵫ":"ue","ꝸ":"um","ⱴ":"v","ꝟ":"v","ṿ":"v","ʋ":"v","ᶌ":"v","ⱱ":"v","ṽ":"v","ꝡ":"vy","ẃ":"w","ŵ":"w","ẅ":"w","ẇ":"w","ẉ":"w","ẁ":"w","ⱳ":"w","ẘ":"w","ẍ":"x","ẋ":"x","ᶍ":"x","ý":"y","ŷ":"y","ÿ":"y","ẏ":"y","ỵ":"y","ỳ":"y","ƴ":"y","ỷ":"y","ỿ":"y","ȳ":"y","ẙ":"y","ɏ":"y","ỹ":"y","ź":"z","ž":"z","ẑ":"z","ʑ":"z","ⱬ":"z","ż":"z","ẓ":"z","ȥ":"z","ẕ":"z","ᵶ":"z","ᶎ":"z","ʐ":"z","ƶ":"z","ɀ":"z","ff":"ff","ffi":"ffi","ffl":"ffl","fi":"fi","fl":"fl","ij":"ij","œ":"oe","st":"st","ₐ":"a","ₑ":"e","ᵢ":"i","ⱼ":"j","ₒ":"o","ᵣ":"r","ᵤ":"u","ᵥ":"v","ₓ":"x"};
String.prototype.latinise=function(){return this.replace(/[^A-Za-z0-9/[/] ]/g,function(a){return Latinise.latin_map[a]||a})};
String.prototype.latinize=String.prototype.latinise;
String.prototype.isLatin=function(){return this==this.latinise()}
Algunos ejemplos:
> "Piqué".latinize();
"Pique"
> "Piqué".isLatin();
false
> "Pique".isLatin();
true
> "Piqué".latinise().isLatin();
true
Para garantizar que el latin_map anterior no se corrompe al copiar / pegar u otras transformaciones, use esta cadena codificada en base64, reemplazando la primera línea de la anterior:
var base64map="eyLDgSI6IkEiLCLEgiI6IkEiLCLhuq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IiwixasiOiJ1Iiwi4bm7IjoidSIsIsWzIjoidSIsIuG2mSI6InUiLCLFryI6InUiLCLFqSI6InUiLCLhubkiOiJ1Iiwi4bm1IjoidSIsIuG1qyI6InVlIiwi6p24IjoidW0iLCLisbQiOiJ2Iiwi6p2fIjoidiIsIuG5vyI6InYiLCLKiyI6InYiLCLhtowiOiJ2Iiwi4rGxIjoidiIsIuG5vSI6InYiLCLqnaEiOiJ2eSIsIuG6gyI6InciLCLFtSI6InciLCLhuoUiOiJ3Iiwi4bqHIjoidyIsIuG6iSI6InciLCLhuoEiOiJ3Iiwi4rGzIjoidyIsIuG6mCI6InciLCLhuo0iOiJ4Iiwi4bqLIjoieCIsIuG2jSI6IngiLCLDvSI6InkiLCLFtyI6InkiLCLDvyI6InkiLCLhuo8iOiJ5Iiwi4bu1IjoieSIsIuG7syI6InkiLCLGtCI6InkiLCLhu7ciOiJ5Iiwi4bu/IjoieSIsIsizIjoieSIsIuG6mSI6InkiLCLJjyI6InkiLCLhu7kiOiJ5IiwixboiOiJ6Iiwixb4iOiJ6Iiwi4bqRIjoieiIsIsqRIjoieiIsIuKxrCI6InoiLCLFvCI6InoiLCLhupMiOiJ6IiwiyKUiOiJ6Iiwi4bqVIjoieiIsIuG1tiI6InoiLCLhto4iOiJ6IiwiypAiOiJ6IiwixrYiOiJ6IiwiyYAiOiJ6Iiwi76yAIjoiZmYiLCLvrIMiOiJmZmkiLCLvrIQiOiJmZmwiLCLvrIEiOiJmaSIsIu+sgiI6ImZsIiwixLMiOiJpaiIsIsWTIjoib2UiLCLvrIYiOiJzdCIsIuKCkCI6ImEiLCLigpEiOiJlIiwi4bWiIjoiaSIsIuKxvCI6ImoiLCLigpIiOiJvIiwi4bWjIjoiciIsIuG1pCI6InUiLCLhtaUiOiJ2Iiwi4oKTIjoieCJ9";
var Latinise={};Latinise.latin_map=JSON.parse(decodeURIComponent(escape(atob(base64map))));
¿Cómo elimino los caracteres acentuados de una cadena? Especialmente en IE6, tuve algo como esto:
accentsTidy = function(s){
var r=s.toLowerCase();
r = r.replace(new RegExp(//s/g),"");
r = r.replace(new RegExp(/[àáâãäå]/g),"a");
r = r.replace(new RegExp(/æ/g),"ae");
r = r.replace(new RegExp(/ç/g),"c");
r = r.replace(new RegExp(/[èéêë]/g),"e");
r = r.replace(new RegExp(/[ìíîï]/g),"i");
r = r.replace(new RegExp(/ñ/g),"n");
r = r.replace(new RegExp(/[òóôõö]/g),"o");
r = r.replace(new RegExp(/œ/g),"oe");
r = r.replace(new RegExp(/[ùúûü]/g),"u");
r = r.replace(new RegExp(/[ýÿ]/g),"y");
r = r.replace(new RegExp(//W/g),"");
return r;
};
pero IE6 me molesta, parece que no le gusta mi expresión regular.
Con ES2015 / ES6 String.Prototype.Normalize() ,
const str = "Crème Brulée"
str.normalize(''NFD'').replace(/[/u0300-/u036f]/g, "")
> ''Creme Brulee''
Dos cosas están sucediendo aquí:
-
normalize()
aNFD
Unicode forma normal descompone grafemas combinados en la combinación de simples. Laè
deCrème
termina expresada comoe
+̀
- Al usar una clase de caracteres de expresiones regulares para coincidir con el rango U + 0300 → U + 036F, ahora es trivial deshacerse de los signos diacríticos que el estándar de Unicode agrupa convenientemente como el bloque de Unicode de marcas diacríticas combinadas.
Ver comentario para pruebas de rendimiento.
Alternativamente, si solo quieres clasificar
Intl.Collator tiene suficiente soporte técnico ~ 85% en este momento , un polyfill también está disponible here pero no lo he probado.
const c = new Intl.Collator();
[''creme brulee'', ''crème brulée'', ''crame brulai'', ''crome brouillé'',
''creme brulay'', ''creme brulfé'', ''creme bruléa''].sort(c.compare)
[ ''crame brulai'',''creme brulay'',''creme bruléa'',''creme brulee'',
''crème brulée'',''creme brulfé'',''crome brouillé'' ]
[''creme brulee'', ''crème brulée'', ''crame brulai'', ''crome brouillé''].sort((a,b) => a>b)
["crame brulai", "creme brulee", "crome brouillé", "crème brulée"]
Modifiqué ligeramente la versión de khel por una razón: cada análisis / reemplazo de expresiones regulares costará operaciones O (n), donde n es el número de caracteres en el texto de destino. Pero, regexp no es exactamente lo que necesitamos. Asi que:
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var defaultDiacriticsRemovalMap = [
{''base'':''A'', ''letters'':''/u0041/u24B6/uFF21/u00C0/u00C1/u00C2/u1EA6/u1EA4/u1EAA/u1EA8/u00C3/u0100/u0102/u1EB0/u1EAE/u1EB4/u1EB2/u0226/u01E0/u00C4/u01DE/u1EA2/u00C5/u01FA/u01CD/u0200/u0202/u1EA0/u1EAC/u1EB6/u1E00/u0104/u023A/u2C6F''},
{''base'':''AA'',''letters'':''/uA732''},
{''base'':''AE'',''letters'':''/u00C6/u01FC/u01E2''},
{''base'':''AO'',''letters'':''/uA734''},
{''base'':''AU'',''letters'':''/uA736''},
{''base'':''AV'',''letters'':''/uA738/uA73A''},
{''base'':''AY'',''letters'':''/uA73C''},
{''base'':''B'', ''letters'':''/u0042/u24B7/uFF22/u1E02/u1E04/u1E06/u0243/u0182/u0181''},
{''base'':''C'', ''letters'':''/u0043/u24B8/uFF23/u0106/u0108/u010A/u010C/u00C7/u1E08/u0187/u023B/uA73E''},
{''base'':''D'', ''letters'':''/u0044/u24B9/uFF24/u1E0A/u010E/u1E0C/u1E10/u1E12/u1E0E/u0110/u018B/u018A/u0189/uA779/u00D0''},
{''base'':''DZ'',''letters'':''/u01F1/u01C4''},
{''base'':''Dz'',''letters'':''/u01F2/u01C5''},
{''base'':''E'', ''letters'':''/u0045/u24BA/uFF25/u00C8/u00C9/u00CA/u1EC0/u1EBE/u1EC4/u1EC2/u1EBC/u0112/u1E14/u1E16/u0114/u0116/u00CB/u1EBA/u011A/u0204/u0206/u1EB8/u1EC6/u0228/u1E1C/u0118/u1E18/u1E1A/u0190/u018E''},
{''base'':''F'', ''letters'':''/u0046/u24BB/uFF26/u1E1E/u0191/uA77B''},
{''base'':''G'', ''letters'':''/u0047/u24BC/uFF27/u01F4/u011C/u1E20/u011E/u0120/u01E6/u0122/u01E4/u0193/uA7A0/uA77D/uA77E''},
{''base'':''H'', ''letters'':''/u0048/u24BD/uFF28/u0124/u1E22/u1E26/u021E/u1E24/u1E28/u1E2A/u0126/u2C67/u2C75/uA78D''},
{''base'':''I'', ''letters'':''/u0049/u24BE/uFF29/u00CC/u00CD/u00CE/u0128/u012A/u012C/u0130/u00CF/u1E2E/u1EC8/u01CF/u0208/u020A/u1ECA/u012E/u1E2C/u0197''},
{''base'':''J'', ''letters'':''/u004A/u24BF/uFF2A/u0134/u0248''},
{''base'':''K'', ''letters'':''/u004B/u24C0/uFF2B/u1E30/u01E8/u1E32/u0136/u1E34/u0198/u2C69/uA740/uA742/uA744/uA7A2''},
{''base'':''L'', ''letters'':''/u004C/u24C1/uFF2C/u013F/u0139/u013D/u1E36/u1E38/u013B/u1E3C/u1E3A/u0141/u023D/u2C62/u2C60/uA748/uA746/uA780''},
{''base'':''LJ'',''letters'':''/u01C7''},
{''base'':''Lj'',''letters'':''/u01C8''},
{''base'':''M'', ''letters'':''/u004D/u24C2/uFF2D/u1E3E/u1E40/u1E42/u2C6E/u019C''},
{''base'':''N'', ''letters'':''/u004E/u24C3/uFF2E/u01F8/u0143/u00D1/u1E44/u0147/u1E46/u0145/u1E4A/u1E48/u0220/u019D/uA790/uA7A4''},
{''base'':''NJ'',''letters'':''/u01CA''},
{''base'':''Nj'',''letters'':''/u01CB''},
{''base'':''O'', ''letters'':''/u004F/u24C4/uFF2F/u00D2/u00D3/u00D4/u1ED2/u1ED0/u1ED6/u1ED4/u00D5/u1E4C/u022C/u1E4E/u014C/u1E50/u1E52/u014E/u022E/u0230/u00D6/u022A/u1ECE/u0150/u01D1/u020C/u020E/u01A0/u1EDC/u1EDA/u1EE0/u1EDE/u1EE2/u1ECC/u1ED8/u01EA/u01EC/u00D8/u01FE/u0186/u019F/uA74A/uA74C''},
{''base'':''OI'',''letters'':''/u01A2''},
{''base'':''OO'',''letters'':''/uA74E''},
{''base'':''OU'',''letters'':''/u0222''},
{''base'':''OE'',''letters'':''/u008C/u0152''},
{''base'':''oe'',''letters'':''/u009C/u0153''},
{''base'':''P'', ''letters'':''/u0050/u24C5/uFF30/u1E54/u1E56/u01A4/u2C63/uA750/uA752/uA754''},
{''base'':''Q'', ''letters'':''/u0051/u24C6/uFF31/uA756/uA758/u024A''},
{''base'':''R'', ''letters'':''/u0052/u24C7/uFF32/u0154/u1E58/u0158/u0210/u0212/u1E5A/u1E5C/u0156/u1E5E/u024C/u2C64/uA75A/uA7A6/uA782''},
{''base'':''S'', ''letters'':''/u0053/u24C8/uFF33/u1E9E/u015A/u1E64/u015C/u1E60/u0160/u1E66/u1E62/u1E68/u0218/u015E/u2C7E/uA7A8/uA784''},
{''base'':''T'', ''letters'':''/u0054/u24C9/uFF34/u1E6A/u0164/u1E6C/u021A/u0162/u1E70/u1E6E/u0166/u01AC/u01AE/u023E/uA786''},
{''base'':''TZ'',''letters'':''/uA728''},
{''base'':''U'', ''letters'':''/u0055/u24CA/uFF35/u00D9/u00DA/u00DB/u0168/u1E78/u016A/u1E7A/u016C/u00DC/u01DB/u01D7/u01D5/u01D9/u1EE6/u016E/u0170/u01D3/u0214/u0216/u01AF/u1EEA/u1EE8/u1EEE/u1EEC/u1EF0/u1EE4/u1E72/u0172/u1E76/u1E74/u0244''},
{''base'':''V'', ''letters'':''/u0056/u24CB/uFF36/u1E7C/u1E7E/u01B2/uA75E/u0245''},
{''base'':''VY'',''letters'':''/uA760''},
{''base'':''W'', ''letters'':''/u0057/u24CC/uFF37/u1E80/u1E82/u0174/u1E86/u1E84/u1E88/u2C72''},
{''base'':''X'', ''letters'':''/u0058/u24CD/uFF38/u1E8A/u1E8C''},
{''base'':''Y'', ''letters'':''/u0059/u24CE/uFF39/u1EF2/u00DD/u0176/u1EF8/u0232/u1E8E/u0178/u1EF6/u1EF4/u01B3/u024E/u1EFE''},
{''base'':''Z'', ''letters'':''/u005A/u24CF/uFF3A/u0179/u1E90/u017B/u017D/u1E92/u1E94/u01B5/u0224/u2C7F/u2C6B/uA762''},
{''base'':''a'', ''letters'':''/u0061/u24D0/uFF41/u1E9A/u00E0/u00E1/u00E2/u1EA7/u1EA5/u1EAB/u1EA9/u00E3/u0101/u0103/u1EB1/u1EAF/u1EB5/u1EB3/u0227/u01E1/u00E4/u01DF/u1EA3/u00E5/u01FB/u01CE/u0201/u0203/u1EA1/u1EAD/u1EB7/u1E01/u0105/u2C65/u0250''},
{''base'':''aa'',''letters'':''/uA733''},
{''base'':''ae'',''letters'':''/u00E6/u01FD/u01E3''},
{''base'':''ao'',''letters'':''/uA735''},
{''base'':''au'',''letters'':''/uA737''},
{''base'':''av'',''letters'':''/uA739/uA73B''},
{''base'':''ay'',''letters'':''/uA73D''},
{''base'':''b'', ''letters'':''/u0062/u24D1/uFF42/u1E03/u1E05/u1E07/u0180/u0183/u0253''},
{''base'':''c'', ''letters'':''/u0063/u24D2/uFF43/u0107/u0109/u010B/u010D/u00E7/u1E09/u0188/u023C/uA73F/u2184''},
{''base'':''d'', ''letters'':''/u0064/u24D3/uFF44/u1E0B/u010F/u1E0D/u1E11/u1E13/u1E0F/u0111/u018C/u0256/u0257/uA77A''},
{''base'':''dz'',''letters'':''/u01F3/u01C6''},
{''base'':''e'', ''letters'':''/u0065/u24D4/uFF45/u00E8/u00E9/u00EA/u1EC1/u1EBF/u1EC5/u1EC3/u1EBD/u0113/u1E15/u1E17/u0115/u0117/u00EB/u1EBB/u011B/u0205/u0207/u1EB9/u1EC7/u0229/u1E1D/u0119/u1E19/u1E1B/u0247/u025B/u01DD''},
{''base'':''f'', ''letters'':''/u0066/u24D5/uFF46/u1E1F/u0192/uA77C''},
{''base'':''g'', ''letters'':''/u0067/u24D6/uFF47/u01F5/u011D/u1E21/u011F/u0121/u01E7/u0123/u01E5/u0260/uA7A1/u1D79/uA77F''},
{''base'':''h'', ''letters'':''/u0068/u24D7/uFF48/u0125/u1E23/u1E27/u021F/u1E25/u1E29/u1E2B/u1E96/u0127/u2C68/u2C76/u0265''},
{''base'':''hv'',''letters'':''/u0195''},
{''base'':''i'', ''letters'':''/u0069/u24D8/uFF49/u00EC/u00ED/u00EE/u0129/u012B/u012D/u00EF/u1E2F/u1EC9/u01D0/u0209/u020B/u1ECB/u012F/u1E2D/u0268/u0131''},
{''base'':''j'', ''letters'':''/u006A/u24D9/uFF4A/u0135/u01F0/u0249''},
{''base'':''k'', ''letters'':''/u006B/u24DA/uFF4B/u1E31/u01E9/u1E33/u0137/u1E35/u0199/u2C6A/uA741/uA743/uA745/uA7A3''},
{''base'':''l'', ''letters'':''/u006C/u24DB/uFF4C/u0140/u013A/u013E/u1E37/u1E39/u013C/u1E3D/u1E3B/u017F/u0142/u019A/u026B/u2C61/uA749/uA781/uA747''},
{''base'':''lj'',''letters'':''/u01C9''},
{''base'':''m'', ''letters'':''/u006D/u24DC/uFF4D/u1E3F/u1E41/u1E43/u0271/u026F''},
{''base'':''n'', ''letters'':''/u006E/u24DD/uFF4E/u01F9/u0144/u00F1/u1E45/u0148/u1E47/u0146/u1E4B/u1E49/u019E/u0272/u0149/uA791/uA7A5''},
{''base'':''nj'',''letters'':''/u01CC''},
{''base'':''o'', ''letters'':''/u006F/u24DE/uFF4F/u00F2/u00F3/u00F4/u1ED3/u1ED1/u1ED7/u1ED5/u00F5/u1E4D/u022D/u1E4F/u014D/u1E51/u1E53/u014F/u022F/u0231/u00F6/u022B/u1ECF/u0151/u01D2/u020D/u020F/u01A1/u1EDD/u1EDB/u1EE1/u1EDF/u1EE3/u1ECD/u1ED9/u01EB/u01ED/u00F8/u01FF/u0254/uA74B/uA74D/u0275''},
{''base'':''oi'',''letters'':''/u01A3''},
{''base'':''ou'',''letters'':''/u0223''},
{''base'':''oo'',''letters'':''/uA74F''},
{''base'':''p'',''letters'':''/u0070/u24DF/uFF50/u1E55/u1E57/u01A5/u1D7D/uA751/uA753/uA755''},
{''base'':''q'',''letters'':''/u0071/u24E0/uFF51/u024B/uA757/uA759''},
{''base'':''r'',''letters'':''/u0072/u24E1/uFF52/u0155/u1E59/u0159/u0211/u0213/u1E5B/u1E5D/u0157/u1E5F/u024D/u027D/uA75B/uA7A7/uA783''},
{''base'':''s'',''letters'':''/u0073/u24E2/uFF53/u00DF/u015B/u1E65/u015D/u1E61/u0161/u1E67/u1E63/u1E69/u0219/u015F/u023F/uA7A9/uA785/u1E9B''},
{''base'':''t'',''letters'':''/u0074/u24E3/uFF54/u1E6B/u1E97/u0165/u1E6D/u021B/u0163/u1E71/u1E6F/u0167/u01AD/u0288/u2C66/uA787''},
{''base'':''tz'',''letters'':''/uA729''},
{''base'':''u'',''letters'': ''/u0075/u24E4/uFF55/u00F9/u00FA/u00FB/u0169/u1E79/u016B/u1E7B/u016D/u00FC/u01DC/u01D8/u01D6/u01DA/u1EE7/u016F/u0171/u01D4/u0215/u0217/u01B0/u1EEB/u1EE9/u1EEF/u1EED/u1EF1/u1EE5/u1E73/u0173/u1E77/u1E75/u0289''},
{''base'':''v'',''letters'':''/u0076/u24E5/uFF56/u1E7D/u1E7F/u028B/uA75F/u028C''},
{''base'':''vy'',''letters'':''/uA761''},
{''base'':''w'',''letters'':''/u0077/u24E6/uFF57/u1E81/u1E83/u0175/u1E87/u1E85/u1E98/u1E89/u2C73''},
{''base'':''x'',''letters'':''/u0078/u24E7/uFF58/u1E8B/u1E8D''},
{''base'':''y'',''letters'':''/u0079/u24E8/uFF59/u1EF3/u00FD/u0177/u1EF9/u0233/u1E8F/u00FF/u1EF7/u1E99/u1EF5/u01B4/u024F/u1EFF''},
{''base'':''z'',''letters'':''/u007A/u24E9/uFF5A/u017A/u1E91/u017C/u017E/u1E93/u1E95/u01B6/u0225/u0240/u2C6C/uA763''}
];
var diacriticsMap = {};
for (var i=0; i < defaultDiacriticsRemovalMap .length; i++){
var letters = defaultDiacriticsRemovalMap [i].letters;
for (var j=0; j < letters.length ; j++){
diacriticsMap[letters[j]] = defaultDiacriticsRemovalMap [i].base;
}
}
// "what?" version ... http://jsperf.com/diacritics/12
function removeDiacritics (str) {
return str.replace(/[^/u0000-/u007E]/g, function(a){
return diacriticsMap[a] || a;
});
}
var paragraph = "L''avantage d''utiliser le lorem ipsum est bien évidemment de pouvoir créer des maquettes ou de remplir un site internet de contenus qui présentent un rendu s''approchant un maximum du rendu final. /n Par défaut lorem ipsum ne contient pas d''accent ni de caractères spéciaux contrairement à la langue française qui en contient beaucoup. C''est sur ce critère que nous proposons une solution avec cet outil qui générant du faux-texte lorem ipsum mais avec en plus, des caractères spéciaux tel que les accents ou certains symboles utiles pour la langue française. /n L''utilisation du lorem standard est facile d’utilisation mais lorsque le futur client utilisera votre logiciel il se peut que certains caractères spéciaux ou qu''un accent ne soient pas codés correctement. /n Cette page a pour but donc de pouvoir perdre le moins de temps possible et donc de tester directement si tous les encodages de base de donnée ou des sites sont les bons de plus il permet de récuperer un code css avec le texte formaté !";
alert(removeDiacritics(paragraph));
Para probar mi teoría, escribí una prueba en http://jsperf.com/diacritics/12 . Resultados:
Pruebas en Chrome 28.0.1500.95 de 32 bits en Windows 8 de 64 bits:
Usando Regexp
4,558 ops / sec ± 4.16%. 37% más lento
Estilo de generador de cadenas
7,308 ops / sec ± 4.88%. lo más rápido
Actualizar
Pruebas en Chrome 33.0.1750 en Windows 8 de 64 bits:
Usando Regexp
5,260 ± 1.25% ops / sec 76% más lento
Usando la versión @skerit
22,138 ± 2.12% ops / seg más rápido
Actualización - 19/03/2014
Añadiendo diacríticos "OE" faltantes.
Actualización - 27/03/2014
Usando una forma más rápida de atravesar una cuerda usando js - "¿Qué?" Versión
Actualización - 14/05/2014
Wiki de la comunidad
Una versión más completa con soporte sensible a las mayúsculas, ligaduras y todo eso. Fuente original en: http://lehelk.com/2011/05/06/script-to-remove-diacritics/
var defaultDiacriticsRemovalMap = [
{''base'':''A'', ''letters'':/[/u0041/u24B6/uFF21/u00C0/u00C1/u00C2/u1EA6/u1EA4/u1EAA/u1EA8/u00C3/u0100/u0102/u1EB0/u1EAE/u1EB4/u1EB2/u0226/u01E0/u00C4/u01DE/u1EA2/u00C5/u01FA/u01CD/u0200/u0202/u1EA0/u1EAC/u1EB6/u1E00/u0104/u023A/u2C6F]/g},
{''base'':''AA'',''letters'':/[/uA732]/g},
{''base'':''AE'',''letters'':/[/u00C6/u01FC/u01E2]/g},
{''base'':''AO'',''letters'':/[/uA734]/g},
{''base'':''AU'',''letters'':/[/uA736]/g},
{''base'':''AV'',''letters'':/[/uA738/uA73A]/g},
{''base'':''AY'',''letters'':/[/uA73C]/g},
{''base'':''B'', ''letters'':/[/u0042/u24B7/uFF22/u1E02/u1E04/u1E06/u0243/u0182/u0181]/g},
{''base'':''C'', ''letters'':/[/u0043/u24B8/uFF23/u0106/u0108/u010A/u010C/u00C7/u1E08/u0187/u023B/uA73E]/g},
{''base'':''D'', ''letters'':/[/u0044/u24B9/uFF24/u1E0A/u010E/u1E0C/u1E10/u1E12/u1E0E/u0110/u018B/u018A/u0189/uA779]/g},
{''base'':''DZ'',''letters'':/[/u01F1/u01C4]/g},
{''base'':''Dz'',''letters'':/[/u01F2/u01C5]/g},
{''base'':''E'', ''letters'':/[/u0045/u24BA/uFF25/u00C8/u00C9/u00CA/u1EC0/u1EBE/u1EC4/u1EC2/u1EBC/u0112/u1E14/u1E16/u0114/u0116/u00CB/u1EBA/u011A/u0204/u0206/u1EB8/u1EC6/u0228/u1E1C/u0118/u1E18/u1E1A/u0190/u018E]/g},
{''base'':''F'', ''letters'':/[/u0046/u24BB/uFF26/u1E1E/u0191/uA77B]/g},
{''base'':''G'', ''letters'':/[/u0047/u24BC/uFF27/u01F4/u011C/u1E20/u011E/u0120/u01E6/u0122/u01E4/u0193/uA7A0/uA77D/uA77E]/g},
{''base'':''H'', ''letters'':/[/u0048/u24BD/uFF28/u0124/u1E22/u1E26/u021E/u1E24/u1E28/u1E2A/u0126/u2C67/u2C75/uA78D]/g},
{''base'':''I'', ''letters'':/[/u0049/u24BE/uFF29/u00CC/u00CD/u00CE/u0128/u012A/u012C/u0130/u00CF/u1E2E/u1EC8/u01CF/u0208/u020A/u1ECA/u012E/u1E2C/u0197]/g},
{''base'':''J'', ''letters'':/[/u004A/u24BF/uFF2A/u0134/u0248]/g},
{''base'':''K'', ''letters'':/[/u004B/u24C0/uFF2B/u1E30/u01E8/u1E32/u0136/u1E34/u0198/u2C69/uA740/uA742/uA744/uA7A2]/g},
{''base'':''L'', ''letters'':/[/u004C/u24C1/uFF2C/u013F/u0139/u013D/u1E36/u1E38/u013B/u1E3C/u1E3A/u0141/u023D/u2C62/u2C60/uA748/uA746/uA780]/g},
{''base'':''LJ'',''letters'':/[/u01C7]/g},
{''base'':''Lj'',''letters'':/[/u01C8]/g},
{''base'':''M'', ''letters'':/[/u004D/u24C2/uFF2D/u1E3E/u1E40/u1E42/u2C6E/u019C]/g},
{''base'':''N'', ''letters'':/[/u004E/u24C3/uFF2E/u01F8/u0143/u00D1/u1E44/u0147/u1E46/u0145/u1E4A/u1E48/u0220/u019D/uA790/uA7A4]/g},
{''base'':''NJ'',''letters'':/[/u01CA]/g},
{''base'':''Nj'',''letters'':/[/u01CB]/g},
{''base'':''O'', ''letters'':/[/u004F/u24C4/uFF2F/u00D2/u00D3/u00D4/u1ED2/u1ED0/u1ED6/u1ED4/u00D5/u1E4C/u022C/u1E4E/u014C/u1E50/u1E52/u014E/u022E/u0230/u00D6/u022A/u1ECE/u0150/u01D1/u020C/u020E/u01A0/u1EDC/u1EDA/u1EE0/u1EDE/u1EE2/u1ECC/u1ED8/u01EA/u01EC/u00D8/u01FE/u0186/u019F/uA74A/uA74C]/g},
{''base'':''OI'',''letters'':/[/u01A2]/g},
{''base'':''OO'',''letters'':/[/uA74E]/g},
{''base'':''OU'',''letters'':/[/u0222]/g},
{''base'':''P'', ''letters'':/[/u0050/u24C5/uFF30/u1E54/u1E56/u01A4/u2C63/uA750/uA752/uA754]/g},
{''base'':''Q'', ''letters'':/[/u0051/u24C6/uFF31/uA756/uA758/u024A]/g},
{''base'':''R'', ''letters'':/[/u0052/u24C7/uFF32/u0154/u1E58/u0158/u0210/u0212/u1E5A/u1E5C/u0156/u1E5E/u024C/u2C64/uA75A/uA7A6/uA782]/g},
{''base'':''S'', ''letters'':/[/u0053/u24C8/uFF33/u1E9E/u015A/u1E64/u015C/u1E60/u0160/u1E66/u1E62/u1E68/u0218/u015E/u2C7E/uA7A8/uA784]/g},
{''base'':''T'', ''letters'':/[/u0054/u24C9/uFF34/u1E6A/u0164/u1E6C/u021A/u0162/u1E70/u1E6E/u0166/u01AC/u01AE/u023E/uA786]/g},
{''base'':''TZ'',''letters'':/[/uA728]/g},
{''base'':''U'', ''letters'':/[/u0055/u24CA/uFF35/u00D9/u00DA/u00DB/u0168/u1E78/u016A/u1E7A/u016C/u00DC/u01DB/u01D7/u01D5/u01D9/u1EE6/u016E/u0170/u01D3/u0214/u0216/u01AF/u1EEA/u1EE8/u1EEE/u1EEC/u1EF0/u1EE4/u1E72/u0172/u1E76/u1E74/u0244]/g},
{''base'':''V'', ''letters'':/[/u0056/u24CB/uFF36/u1E7C/u1E7E/u01B2/uA75E/u0245]/g},
{''base'':''VY'',''letters'':/[/uA760]/g},
{''base'':''W'', ''letters'':/[/u0057/u24CC/uFF37/u1E80/u1E82/u0174/u1E86/u1E84/u1E88/u2C72]/g},
{''base'':''X'', ''letters'':/[/u0058/u24CD/uFF38/u1E8A/u1E8C]/g},
{''base'':''Y'', ''letters'':/[/u0059/u24CE/uFF39/u1EF2/u00DD/u0176/u1EF8/u0232/u1E8E/u0178/u1EF6/u1EF4/u01B3/u024E/u1EFE]/g},
{''base'':''Z'', ''letters'':/[/u005A/u24CF/uFF3A/u0179/u1E90/u017B/u017D/u1E92/u1E94/u01B5/u0224/u2C7F/u2C6B/uA762]/g},
{''base'':''a'', ''letters'':/[/u0061/u24D0/uFF41/u1E9A/u00E0/u00E1/u00E2/u1EA7/u1EA5/u1EAB/u1EA9/u00E3/u0101/u0103/u1EB1/u1EAF/u1EB5/u1EB3/u0227/u01E1/u00E4/u01DF/u1EA3/u00E5/u01FB/u01CE/u0201/u0203/u1EA1/u1EAD/u1EB7/u1E01/u0105/u2C65/u0250]/g},
{''base'':''aa'',''letters'':/[/uA733]/g},
{''base'':''ae'',''letters'':/[/u00E6/u01FD/u01E3]/g},
{''base'':''ao'',''letters'':/[/uA735]/g},
{''base'':''au'',''letters'':/[/uA737]/g},
{''base'':''av'',''letters'':/[/uA739/uA73B]/g},
{''base'':''ay'',''letters'':/[/uA73D]/g},
{''base'':''b'', ''letters'':/[/u0062/u24D1/uFF42/u1E03/u1E05/u1E07/u0180/u0183/u0253]/g},
{''base'':''c'', ''letters'':/[/u0063/u24D2/uFF43/u0107/u0109/u010B/u010D/u00E7/u1E09/u0188/u023C/uA73F/u2184]/g},
{''base'':''d'', ''letters'':/[/u0064/u24D3/uFF44/u1E0B/u010F/u1E0D/u1E11/u1E13/u1E0F/u0111/u018C/u0256/u0257/uA77A]/g},
{''base'':''dz'',''letters'':/[/u01F3/u01C6]/g},
{''base'':''e'', ''letters'':/[/u0065/u24D4/uFF45/u00E8/u00E9/u00EA/u1EC1/u1EBF/u1EC5/u1EC3/u1EBD/u0113/u1E15/u1E17/u0115/u0117/u00EB/u1EBB/u011B/u0205/u0207/u1EB9/u1EC7/u0229/u1E1D/u0119/u1E19/u1E1B/u0247/u025B/u01DD]/g},
{''base'':''f'', ''letters'':/[/u0066/u24D5/uFF46/u1E1F/u0192/uA77C]/g},
{''base'':''g'', ''letters'':/[/u0067/u24D6/uFF47/u01F5/u011D/u1E21/u011F/u0121/u01E7/u0123/u01E5/u0260/uA7A1/u1D79/uA77F]/g},
{''base'':''h'', ''letters'':/[/u0068/u24D7/uFF48/u0125/u1E23/u1E27/u021F/u1E25/u1E29/u1E2B/u1E96/u0127/u2C68/u2C76/u0265]/g},
{''base'':''hv'',''letters'':/[/u0195]/g},
{''base'':''i'', ''letters'':/[/u0069/u24D8/uFF49/u00EC/u00ED/u00EE/u0129/u012B/u012D/u00EF/u1E2F/u1EC9/u01D0/u0209/u020B/u1ECB/u012F/u1E2D/u0268/u0131]/g},
{''base'':''j'', ''letters'':/[/u006A/u24D9/uFF4A/u0135/u01F0/u0249]/g},
{''base'':''k'', ''letters'':/[/u006B/u24DA/uFF4B/u1E31/u01E9/u1E33/u0137/u1E35/u0199/u2C6A/uA741/uA743/uA745/uA7A3]/g},
{''base'':''l'', ''letters'':/[/u006C/u24DB/uFF4C/u0140/u013A/u013E/u1E37/u1E39/u013C/u1E3D/u1E3B/u017F/u0142/u019A/u026B/u2C61/uA749/uA781/uA747]/g},
{''base'':''lj'',''letters'':/[/u01C9]/g},
{''base'':''m'', ''letters'':/[/u006D/u24DC/uFF4D/u1E3F/u1E41/u1E43/u0271/u026F]/g},
{''base'':''n'', ''letters'':/[/u006E/u24DD/uFF4E/u01F9/u0144/u00F1/u1E45/u0148/u1E47/u0146/u1E4B/u1E49/u019E/u0272/u0149/uA791/uA7A5]/g},
{''base'':''nj'',''letters'':/[/u01CC]/g},
{''base'':''o'', ''letters'':/[/u006F/u24DE/uFF4F/u00F2/u00F3/u00F4/u1ED3/u1ED1/u1ED7/u1ED5/u00F5/u1E4D/u022D/u1E4F/u014D/u1E51/u1E53/u014F/u022F/u0231/u00F6/u022B/u1ECF/u0151/u01D2/u020D/u020F/u01A1/u1EDD/u1EDB/u1EE1/u1EDF/u1EE3/u1ECD/u1ED9/u01EB/u01ED/u00F8/u01FF/u0254/uA74B/uA74D/u0275]/g},
{''base'':''oi'',''letters'':/[/u01A3]/g},
{''base'':''ou'',''letters'':/[/u0223]/g},
{''base'':''oo'',''letters'':/[/uA74F]/g},
{''base'':''p'',''letters'':/[/u0070/u24DF/uFF50/u1E55/u1E57/u01A5/u1D7D/uA751/uA753/uA755]/g},
{''base'':''q'',''letters'':/[/u0071/u24E0/uFF51/u024B/uA757/uA759]/g},
{''base'':''r'',''letters'':/[/u0072/u24E1/uFF52/u0155/u1E59/u0159/u0211/u0213/u1E5B/u1E5D/u0157/u1E5F/u024D/u027D/uA75B/uA7A7/uA783]/g},
{''base'':''s'',''letters'':/[/u0073/u24E2/uFF53/u00DF/u015B/u1E65/u015D/u1E61/u0161/u1E67/u1E63/u1E69/u0219/u015F/u023F/uA7A9/uA785/u1E9B]/g},
{''base'':''t'',''letters'':/[/u0074/u24E3/uFF54/u1E6B/u1E97/u0165/u1E6D/u021B/u0163/u1E71/u1E6F/u0167/u01AD/u0288/u2C66/uA787]/g},
{''base'':''tz'',''letters'':/[/uA729]/g},
{''base'':''u'',''letters'':/[/u0075/u24E4/uFF55/u00F9/u00FA/u00FB/u0169/u1E79/u016B/u1E7B/u016D/u00FC/u01DC/u01D8/u01D6/u01DA/u1EE7/u016F/u0171/u01D4/u0215/u0217/u01B0/u1EEB/u1EE9/u1EEF/u1EED/u1EF1/u1EE5/u1E73/u0173/u1E77/u1E75/u0289]/g},
{''base'':''v'',''letters'':/[/u0076/u24E5/uFF56/u1E7D/u1E7F/u028B/uA75F/u028C]/g},
{''base'':''vy'',''letters'':/[/uA761]/g},
{''base'':''w'',''letters'':/[/u0077/u24E6/uFF57/u1E81/u1E83/u0175/u1E87/u1E85/u1E98/u1E89/u2C73]/g},
{''base'':''x'',''letters'':/[/u0078/u24E7/uFF58/u1E8B/u1E8D]/g},
{''base'':''y'',''letters'':/[/u0079/u24E8/uFF59/u1EF3/u00FD/u0177/u1EF9/u0233/u1E8F/u00FF/u1EF7/u1E99/u1EF5/u01B4/u024F/u1EFF]/g},
{''base'':''z'',''letters'':/[/u007A/u24E9/uFF5A/u017A/u1E91/u017C/u017E/u1E93/u1E95/u01B6/u0225/u0240/u2C6C/uA763]/g}
];
var changes;
function removeDiacritics (str) {
if(!changes) {
changes = defaultDiacriticsRemovalMap;
}
for(var i=0; i<changes.length; i++) {
str = str.replace(changes[i].letters, changes[i].base);
}
return str;
}
Aquí hay una solución muy simple sin demasiado código usando un mapa muy simple de signos diacríticos que incluye algunos o todos los mapas equivalentes a ascii que contienen más de un carácter, es decir, Æ => AE, ffi => ffi, etc ... También se incluyen algunos Pruebas funcionales muy básicas.
var diacriticsMap = {
''/u00C0'': ''A'', // À => A
''/u00C1'': ''A'', // Á => A
''/u00C2'': ''A'', // Â => A
''/u00C3'': ''A'', // Ã => A
''/u00C4'': ''A'', // Ä => A
''/u00C5'': ''A'', // Å => A
''/u00C6'': ''AE'', // Æ => AE
''/u00C7'': ''C'', // Ç => C
''/u00C8'': ''E'', // È => E
''/u00C9'': ''E'', // É => E
''/u00CA'': ''E'', // Ê => E
''/u00CB'': ''E'', // Ë => E
''/u00CC'': ''I'', // Ì => I
''/u00CD'': ''I'', // Í => I
''/u00CE'': ''I'', // Î => I
''/u00CF'': ''I'', // Ï => I
''/u0132'': ''IJ'', // IJ => IJ
''/u00D0'': ''D'', // Ð => D
''/u00D1'': ''N'', // Ñ => N
''/u00D2'': ''O'', // Ò => O
''/u00D3'': ''O'', // Ó => O
''/u00D4'': ''O'', // Ô => O
''/u00D5'': ''O'', // Õ => O
''/u00D6'': ''O'', // Ö => O
''/u00D8'': ''O'', // Ø => O
''/u0152'': ''OE'', // Œ => OE
''/u00DE'': ''TH'', // Þ => TH
''/u00D9'': ''U'', // Ù => U
''/u00DA'': ''U'', // Ú => U
''/u00DB'': ''U'', // Û => U
''/u00DC'': ''U'', // Ü => U
''/u00DD'': ''Y'', // Ý => Y
''/u0178'': ''Y'', // Ÿ => Y
''/u00E0'': ''a'', // à => a
''/u00E1'': ''a'', // á => a
''/u00E2'': ''a'', // â => a
''/u00E3'': ''a'', // ã => a
''/u00E4'': ''a'', // ä => a
''/u00E5'': ''a'', // å => a
''/u00E6'': ''ae'', // æ => ae
''/u00E7'': ''c'', // ç => c
''/u00E8'': ''e'', // è => e
''/u00E9'': ''e'', // é => e
''/u00EA'': ''e'', // ê => e
''/u00EB'': ''e'', // ë => e
''/u00EC'': ''i'', // ì => i
''/u00ED'': ''i'', // í => i
''/u00EE'': ''i'', // î => i
''/u00EF'': ''i'', // ï => i
''/u0133'': ''ij'', // ij => ij
''/u00F0'': ''d'', // ð => d
''/u00F1'': ''n'', // ñ => n
''/u00F2'': ''o'', // ò => o
''/u00F3'': ''o'', // ó => o
''/u00F4'': ''o'', // ô => o
''/u00F5'': ''o'', // õ => o
''/u00F6'': ''o'', // ö => o
''/u00F8'': ''o'', // ø => o
''/u0153'': ''oe'', // œ => oe
''/u00DF'': ''ss'', // ß => ss
''/u00FE'': ''th'', // þ => th
''/u00F9'': ''u'', // ù => u
''/u00FA'': ''u'', // ú => u
''/u00FB'': ''u'', // û => u
''/u00FC'': ''u'', // ü => u
''/u00FD'': ''y'', // ý => y
''/u00FF'': ''y'', // ÿ => y
''/uFB00'': ''ff'', // ff => ff
''/uFB01'': ''fi'', // fi => fi
''/uFB02'': ''fl'', // fl => fl
''/uFB03'': ''ffi'', // ffi => ffi
''/uFB04'': ''ffl'', // ffl => ffl
''/uFB05'': ''ft'', // ſt => ft
''/uFB06'': ''st'' // st => st
};
function replaceDiacritics(str) {
var returnStr = '''';
if(str) {
for (var i = 0; i < str.length; i++) {
if (diacriticsMap[str[i]]) {
returnStr += diacriticsMap[str[i]];
} else {
returnStr += str[i];
}
}
}
return returnStr;
}
function testStripDiacritics(input, expected) {
var coChar = replaceDiacritics(input);
console.log(''The character passed in was '' + input);
console.log(''The character that came out was '' + coChar);
console.log(''The character expected was'' + expected);
}
testStripDiacritics(''À'',''A'');
testStripDiacritics(''A'',''A'');
testStripDiacritics(''Æ'',''AE'');
testStripDiacritics(''AE'',''AE'');
testStripDiacritics(''ÇhÀrlËšYŸZŽ'',''ChArlEsYYZZ'');
Código abreviado basado en la excelente solución de Ian Elliott:
accentsTidy = function(s){
var r = s.toLowerCase();
non_asciis = {''a'': ''[àáâãäå]'', ''ae'': ''æ'', ''c'': ''ç'', ''e'': ''[èéêë]'', ''i'': ''[ìíîï]'', ''n'': ''ñ'', ''o'': ''[òóôõö]'', ''oe'': ''œ'', ''u'': ''[ùúûűü]'', ''y'': ''[ýÿ]''};
for (i in non_asciis) { r = r.replace(new RegExp(non_asciis[i], ''g''), i); }
return r;
};
Edición: Código de no trabajo corregido
El formato para el nuevo RegExp es
RegExp(something, ''modifiers'');
Así que querrías
accentsTidy = function(s){
var r=s.toLowerCase();
r = r.replace(new RegExp("//s", ''g''),"");
r = r.replace(new RegExp("[àáâãäå]", ''g''),"a");
r = r.replace(new RegExp("æ", ''g''),"ae");
r = r.replace(new RegExp("ç", ''g''),"c");
r = r.replace(new RegExp("[èéêë]", ''g''),"e");
r = r.replace(new RegExp("[ìíîï]", ''g''),"i");
r = r.replace(new RegExp("ñ", ''g''),"n");
r = r.replace(new RegExp("[òóôõö]", ''g''),"o");
r = r.replace(new RegExp("œ", ''g''),"oe");
r = r.replace(new RegExp("[ùúûü]", ''g''),"u");
r = r.replace(new RegExp("[ýÿ]", ''g''),"y");
r = r.replace(new RegExp("//W", ''g''),"");
return r;
};
Hay mucho por ahí, pero creo que este es simple y lo suficientemente bueno:
function remove_accents(strAccents) {
var strAccents = strAccents.split('''');
var strAccentsOut = new Array();
var strAccentsLen = strAccents.length;
var accents = "ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž";
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
for (var y = 0; y < strAccentsLen; y++) {
if (accents.indexOf(strAccents[y]) != -1) {
strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1);
} else
strAccentsOut[y] = strAccents[y];
}
strAccentsOut = strAccentsOut.join('''');
return strAccentsOut;
}
Si también desea eliminar caracteres especiales y transformar espacios y guiones en guiones bajos, haga lo siguiente:
string = remove_accents(string);
string = string.replace(/[^a-z0-9/s]/gi, '''').replace(/[-/s]/g, ''_'');
Suponiendo que sabes lo que estás haciendo, sospecho que IE6 no está interpretando correctamente la codificación del archivo y, por lo tanto, no reconoce los caracteres que no son ASCII en el archivo:
- Asegúrese de que el archivo se guarda como UTF-8 (por ejemplo)
- Utilice Fiddler o alguna otra herramienta para verificar que el servidor web esté enviando el encabezado HTTP de codificación de contenido correcto.
(Aunque "huele" mal, me gustaría hacer la clasificación, por ejemplo, en el servidor usando algo que tenga en cuenta la ubicación ... pero de todos modos ...)
Una forma más sencilla de reemplazar los diacríticos.
function replaceDiacritics(str){
var diacritics = [
{char: ''A'', base: /[/300-/306]/g},
{char: ''a'', base: /[/340-/346]/g},
{char: ''E'', base: /[/310-/313]/g},
{char: ''e'', base: /[/350-/353]/g},
{char: ''I'', base: /[/314-/317]/g},
{char: ''i'', base: /[/354-/357]/g},
{char: ''O'', base: /[/322-/330]/g},
{char: ''o'', base: /[/362-/370]/g},
{char: ''U'', base: /[/331-/334]/g},
{char: ''u'', base: /[/371-/374]/g},
{char: ''N'', base: /[/321]/g},
{char: ''n'', base: /[/361]/g},
{char: ''C'', base: /[/307]/g},
{char: ''c'', base: /[/347]/g}
]
diacritics.forEach(function(letter){
str = str.replace(letter.base, letter.char);
});
return str;
};
Aquí está mi versión modificada de la versión de lehelk.com que también elimina los elementos HTML que son acentos:
http://jsfiddle.net/billybraga/UHmnf/
Aún no sé sobre el rendimiento, aunque ...
var defaultDiacriticsRemovalMap = [{
''base'': "A",
''letters'': /(A|Ⓐ|A|À|Á|Â|Ầ|Ấ|Ẫ|Ẩ|Ã|Ā|Ă|Ằ|Ắ|Ẵ|Ẳ|Ȧ|Ǡ|Ä|Ǟ|Ả|Å|Ǻ|Ǎ|Ȁ|Ȃ|Ạ|Ậ|Ặ|Ḁ|Ą|Ⱥ|Ɐ|[/u0041/u24B6/uFF21/u00C0/u00C1/u00C2/u1EA6/u1EA4/u1EAA/u1EA8/u00C3/u0100/u0102/u1EB0/u1EAE/u1EB4/u1EB2/u0226/u01E0/u00C4/u01DE/u1EA2/u00C5/u01FA/u01CD/u0200/u0202/u1EA0/u1EAC/u1EB6/u1E00/u0104/u023A/u2C6F])/g},
{
''base'': "AA",
''letters'': /(Ꜳ|[/uA732])/g},
{
''base'': "AE",
''letters'': /(Æ|Ǽ|Ǣ|[/u00C6/u01FC/u01E2])/g},
{
''base'': "AO",
''letters'': /(Ꜵ|[/uA734])/g},
{
''base'': "AU",
''letters'': /(Ꜷ|[/uA736])/g},
{
''base'': "AV",
''letters'': /(Ꜹ|Ꜻ|[/uA738/uA73A])/g},
{
''base'': "AY",
''letters'': /(Ꜽ|[/uA73C])/g},
{
''base'': "B",
''letters'': /(B|Ⓑ|B|Ḃ|Ḅ|Ḇ|Ƀ|Ƃ|Ɓ|[/u0042/u24B7/uFF22/u1E02/u1E04/u1E06/u0243/u0182/u0181])/g},
{
''base'': "C",
''letters'': /(C|Ⓒ|C|Ć|Ĉ|Ċ|Č|Ç|Ḉ|Ƈ|Ȼ|Ꜿ|[/u0043/u24B8/uFF23/u0106/u0108/u010A/u010C/u00C7/u1E08/u0187/u023B/uA73E])/g},
{
''base'': "D",
''letters'': /(D|Ⓓ|D|Ḋ|Ď|Ḍ|Ḑ|Ḓ|Ḏ|Đ|Ƌ|Ɗ|Ɖ|Ꝺ|[/u0044/u24B9/uFF24/u1E0A/u010E/u1E0C/u1E10/u1E12/u1E0E/u0110/u018B/u018A/u0189/uA779])/g},
{
''base'': "DZ",
''letters'': /(DZ|DŽ|[/u01F1/u01C4])/g},
{
''base'': "Dz",
''letters'': /(Dz|Dž|[/u01F2/u01C5])/g},
{
''base'': "E",
''letters'': /(E|Ⓔ|E|È|É|Ê|Ề|Ế|Ễ|Ể|Ẽ|Ē|Ḕ|Ḗ|Ĕ|Ė|Ë|Ẻ|Ě|Ȅ|Ȇ|Ẹ|Ệ|Ȩ|Ḝ|Ę|Ḙ|Ḛ|Ɛ|Ǝ|[/u0045/u24BA/uFF25/u00C8/u00C9/u00CA/u1EC0/u1EBE/u1EC4/u1EC2/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ă|ằ|ắ|ẵ|ẳ|ȧ|ǡ|ä|ǟ|ả|å|ǻ|ǎ|ȁ|ȃ|ạ|ậ|ặ|ḁ|ą|ⱥ|ɐ|[/u0061/u24D0/uFF41/u1E9A/u00E0/u00E1/u00E2/u1EA7/u1EA5/u1EAB/u1EA9/u00E3/u0101/u0103/u1EB1/u1EAF/u1EB5/u1EB3/u0227/u01E1/u00E4/u01DF/u1EA3/u00E5/u01FB/u01CE/u0201/u0203/u1EA1/u1EAD/u1EB7/u1E01/u0105/u2C65/u0250])/g},
{
''base'': "aa",
''letters'': /(ꜳ|[/uA733])/g},
{
''base'': "ae",
''letters'': /(æ|ǽ|ǣ|[/u00E6/u01FD/u01E3])/g},
{
''base'': "ao",
''letters'': /(ꜵ|[/uA735])/g},
{
''base'': "au",
''letters'': /(ꜷ|[/uA737])/g},
{
''base'': "av",
''letters'': /(ꜹ|ꜻ|[/uA739/uA73B])/g},
{
''base'': "ay",
''letters'': /(ꜽ|[/uA73D])/g},
{
''base'': "b",
''letters'': /(b|ⓑ|b|ḃ|ḅ|ḇ|ƀ|ƃ|ɓ|[/u0062/u24D1/uFF42/u1E03/u1E05/u1E07/u0180/u0183/u0253])/g},
{
''base'': "c",
''letters'': /(c|ⓒ|c|ć|ĉ|ċ|č|ç|ḉ|ƈ|ȼ|ꜿ|ↄ|[/u0063/u24D2/uFF43/u0107/u0109/u010B/u010D/u00E7/u1E09/u0188/u023C/uA73F/u2184])/g},
{
''base'': "d",
''letters'': /(d|ⓓ|d|ḋ|ď|ḍ|ḑ|ḓ|ḏ|đ|ƌ|ɖ|ɗ|ꝺ|[/u0064/u24D3/uFF44/u1E0B/u010F/u1E0D/u1E11/u1E13/u1E0F/u0111/u018C/u0256/u0257/uA77A])/g},
{
''base'': "dz",
''letters'': /(dz|dž|[/u01F3/u01C6])/g},
{
''base'': "e",
''letters'': /(e|ⓔ|e|è|é|ê|ề|ế|ễ|ể|ẽ|ē|ḕ|ḗ|ĕ|ė|ë|ẻ|ě|ȅ|ȇ|ẹ|ệ|ȩ|ḝ|ę|ḙ|ḛ|ɇ|ɛ|ǝ|[/u0065/u24D4/uFF45/u00E8/u00E9/u00EA/u1EC1/u1EBF/u1EC5/u1EC3/u1EBD/u0113/u1E15/u1E17/u0115/u0117/u00EB/u1EBB/u011B/u0205/u0207/u1EB9/u1EC7/u0229/u1E1D/u0119/u1E19/u1E1B/u0247/u025B/u01DD])/g},
{
''base'': "f",
''letters'': /(f|ⓕ|f|ḟ|ƒ|ꝼ|[/u0066/u24D5/uFF46/u1E1F/u0192/uA77C])/g},
{
''base'': "g",
''letters'': /(g|ⓖ|g|ǵ|ĝ|ḡ|ğ|ġ|ǧ|ģ|ǥ|ɠ|ꞡ|ᵹ|ꝿ|[/u0067/u24D6/uFF47/u01F5/u011D/u1E21/u011F/u0121/u01E7/u0123/u01E5/u0260/uA7A1/u1D79/uA77F])/g},
{
''base'': "h",
''letters'': /(h|ⓗ|h|ĥ|ḣ|ḧ|ȟ|ḥ|ḩ|ḫ|ẖ|ħ|ⱨ|ⱶ|ɥ|[/u0068/u24D7/uFF48/u0125/u1E23/u1E27/u021F/u1E25/u1E29/u1E2B/u1E96/u0127/u2C68/u2C76/u0265])/g},
{
''base'': "hv",
''letters'': /(ƕ|[/u0195])/g},
{
''base'': "i",
''letters'': /(i|ⓘ|i|ì|í|î|ĩ|ī|ĭ|ï|ḯ|ỉ|ǐ|ȉ|ȋ|ị|į|ḭ|ɨ|ı|[/u0069/u24D8/uFF49/u00EC/u00ED/u00EE/u0129/u012B/u012D/u00EF/u1E2F/u1EC9/u01D0/u0209/u020B/u1ECB/u012F/u1E2D/u0268/u0131])/g},
{
''base'': "j",
''letters'': /(j|ⓙ|j|ĵ|ǰ|ɉ|[/u006A/u24D9/uFF4A/u0135/u01F0/u0249])/g},
{
''base'': "k",
''letters'': /(k|ⓚ|k|ḱ|ǩ|ḳ|ķ|ḵ|ƙ|ⱪ|ꝁ|ꝃ|ꝅ|ꞣ|[/u006B/u24DA/uFF4B/u1E31/u01E9/u1E33/u0137/u1E35/u0199/u2C6A/uA741/uA743/uA745/uA7A3])/g},
{
''base'': "l",
''letters'': /(l|ⓛ|l|ŀ|ĺ|ľ|ḷ|ḹ|ļ|ḽ|ḻ|ſ|ł|ƚ|ɫ|ⱡ|ꝉ|ꞁ|ꝇ|[/u006C/u24DB/uFF4C/u0140/u013A/u013E/u1E37/u1E39/u013C/u1E3D/u1E3B/u017F/u0142/u019A/u026B/u2C61/uA749/uA781/uA747])/g},
{
''base'': "lj",
''letters'': /(lj|[/u01C9])/g},
{
''base'': "m",
''letters'': /(m|ⓜ|m|ḿ|ṁ|ṃ|ɱ|ɯ|[/u006D/u24DC/uFF4D/u1E3F/u1E41/u1E43/u0271/u026F])/g},
{
''base'': "n",
''letters'': /(n|ⓝ|n|ǹ|ń|ñ|ṅ|ň|ṇ|ņ|ṋ|ṉ|ƞ|ɲ|ʼn|ꞑ|ꞥ|[/u006E/u24DD/uFF4E/u01F9/u0144/u00F1/u1E45/u0148/u1E47/u0146/u1E4B/u1E49/u019E/u0272/u0149/uA791/uA7A5])/g},
{
''base'': "nj",
''letters'': /(nj|[/u01CC])/g},
{
''base'': "o",
''letters'': /(o|ⓞ|o|ò|ó|ô|ồ|ố|ỗ|ổ|õ|ṍ|ȭ|ṏ|ō|ṑ|ṓ|ŏ|ȯ|ȱ|ö|ȫ|ỏ|ő|ǒ|ȍ|ȏ|ơ|ờ|ớ|ỡ|ở|ợ|ọ|ộ|ǫ|ǭ|ø|ǿ|ɔ|ꝋ|ꝍ|ɵ|[/u006F/u24DE/uFF4F/u00F2/u00F3/u00F4/u1ED3/u1ED1/u1ED7/u1ED5/u00F5/u1E4D/u022D/u1E4F/u014D/u1E51/u1E53/u014F/u022F/u0231/u00F6/u022B/u1ECF/u0151/u01D2/u020D/u020F/u01A1/u1EDD/u1EDB/u1EE1/u1EDF/u1EE3/u1ECD/u1ED9/u01EB/u01ED/u00F8/u01FF/u0254/uA74B/uA74D/u0275])/g},
{
''base'': "oi",
''letters'': /(ƣ|[/u01A3])/g},
{
''base'': "ou",
''letters'': /(ȣ|[/u0223])/g},
{
''base'': "oo",
''letters'': /(ꝏ|[/uA74F])/g},
{
''base'': "p",
''letters'': /(p|ⓟ|p|ṕ|ṗ|ƥ|ᵽ|ꝑ|ꝓ|ꝕ|[/u0070/u24DF/uFF50/u1E55/u1E57/u01A5/u1D7D/uA751/uA753/uA755])/g},
{
''base'': "q",
''letters'': /(q|ⓠ|q|ɋ|ꝗ|ꝙ|[/u0071/u24E0/uFF51/u024B/uA757/uA759])/g},
{
''base'': "r",
''letters'': /(r|ⓡ|r|ŕ|ṙ|ř|ȑ|ȓ|ṛ|ṝ|ŗ|ṟ|ɍ|ɽ|ꝛ|ꞧ|ꞃ|[/u0072/u24E1/uFF52/u0155/u1E59/u0159/u0211/u0213/u1E5B/u1E5D/u0157/u1E5F/u024D/u027D/uA75B/uA7A7/uA783])/g},
{
''base'': "s",
''letters'': /(s|ⓢ|s|ß|ś|ṥ|ŝ|ṡ|š|ṧ|ṣ|ṩ|ș|ş|ȿ|ꞩ|ꞅ|ẛ|[/u0073/u24E2/uFF53/u00DF/u015B/u1E65/u015D/u1E61/u0161/u1E67/u1E63/u1E69/u0219/u015F/u023F/uA7A9/uA785/u1E9B])/g},
{
''base'': "t",
''letters'': /(t|ⓣ|t|ṫ|ẗ|ť|ṭ|ț|ţ|ṱ|ṯ|ŧ|ƭ|ʈ|ⱦ|ꞇ|[/u0074/u24E3/uFF54/u1E6B/u1E97/u0165/u1E6D/u021B/u0163/u1E71/u1E6F/u0167/u01AD/u0288/u2C66/uA787])/g},
{
''base'': "tz",
''letters'': /(ꜩ|[/uA729])/g},
{
''base'': "u",
''letters'': /(u|ⓤ|u|ù|ú|û|ũ|ṹ|ū|ṻ|ŭ|ü|ǜ|ǘ|ǖ|ǚ|ủ|ů|ű|ǔ|ȕ|ȗ|ư|ừ|ứ|ữ|ử|ự|ụ|ṳ|ų|ṷ|ṵ|ʉ|[/u0075/u24E4/uFF55/u00F9/u00FA/u00FB/u0169/u1E79/u016B/u1E7B/u016D/u00FC/u01DC/u01D8/u01D6/u01DA/u1EE7/u016F/u0171/u01D4/u0215/u0217/u01B0/u1EEB/u1EE9/u1EEF/u1EED/u1EF1/u1EE5/u1E73/u0173/u1E77/u1E75/u0289])/g},
{
''base'': "v",
''letters'': /(v|ⓥ|v|ṽ|ṿ|ʋ|ꝟ|ʌ|[/u0076/u24E5/uFF56/u1E7D/u1E7F/u028B/uA75F/u028C])/g},
{
''base'': "vy",
''letters'': /(ꝡ|[/uA761])/g},
{
''base'': "w",
''letters'': /(w|ⓦ|w|ẁ|ẃ|ŵ|ẇ|ẅ|ẘ|ẉ|ⱳ|[/u0077/u24E6/uFF57/u1E81/u1E83/u0175/u1E87/u1E85/u1E98/u1E89/u2C73])/g},
{
''base'': "x",
''letters'': /(x|ⓧ|x|ẋ|ẍ|[/u0078/u24E7/uFF58/u1E8B/u1E8D])/g},
{
''base'': "y",
''letters'': /(y|ⓨ|y|ỳ|ý|ŷ|ỹ|ȳ|ẏ|ÿ|ỷ|ẙ|ỵ|ƴ|ɏ|ỿ|[/u0079/u24E8/uFF59/u1EF3/u00FD/u0177/u1EF9/u0233/u1E8F/u00FF/u1EF7/u1E99/u1EF5/u01B4/u024F/u1EFF])/g},
{
''base'': "z",
''letters'': /(z|ⓩ|z|ź|ẑ|ż|ž|ẓ|ẕ|ƶ|ȥ|ɀ|ⱬ|ꝣ|[/u007A/u24E9/uFF5A/u017A/u1E91/u017C/u017E/u1E93/u1E95/u01B6/u0225/u0240/u2C6C/uA763])/g}];
function removeDiacritics(str) {
for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
str = str.replace(defaultDiacriticsRemovalMap[i].letters, defaultDiacriticsRemovalMap[i].base);
}
return str;
}
El paquete NPM de remove-accents es una forma bastante fácil de manejar estos problemas:
var input = ''ÀÁÂÃÄÅ'';
var output = removeAccents(input);
console.log(output); // AAAAAA
En NPM hay un paquete para esto: latinize
Es un muy buen paquete para resolver este problema.
Encontré todo esto un poco torpe y no soy demasiado experto en expresiones regulares, así que aquí hay una versión más simple. Sería bastante fácil traducirlo a su lenguaje de servidor favorito, suponiendo que la cadena ya está en Unicode:
// String containing replacement characters for stripping accents
var stripstring =
''AAAAAAACEEEEIIII''+
''DNOOOOO.OUUUUY..''+
''aaaaaaaceeeeiiii''+
''dnooooo.ouuuuy.y''+
''AaAaAaCcCcCcCcDd''+
''DdEeEeEeEeEeGgGg''+
''GgGgHhHhIiIiIiIi''+
''IiIiJjKkkLlLlLlL''+
''lJlNnNnNnnNnOoOo''+
''OoOoRrRrRrSsSsSs''+
''SsTtTtTtUuUuUuUu''+
''UuUuWwYyYZzZzZz.'';
function stripaccents(str){
var answer='''';
for(var i=0;i<str.length;i++){
var ch=str[i];
var chindex=ch.charCodeAt(0)-192; // Index of character code in the strip string
if(chindex>=0 && chindex<stripstring.length){
// Character is within our table, so we can strip the accent...
var outch=stripstring.charAt(chindex);
// ...unless it was shown as a ''.''
if(outch!=''.'')ch=outch;
}
answer+=ch;
}
return answer;
}
Esto lo hizo por mí. JavaScript, Google Apps Scripts, GAS
function normalizetext(text) {
var weird = ''öüóőúéáàűíÖÜÓŐÚÉÁÀŰÍçÇ!@£$%^&*()_+?/*."'';
var normalized = ''ouooueaauiOUOOUEAAUIcC '';
var idoff = -1,new_text = '''';
var lentext = text.toString().length -1
for (i = 0; i <= lentext; i++) {
idoff = weird.search(text.charAt(i));
if (idoff == -1) {
new_text = new_text + text.charAt(i);
} else {
new_text = new_text + normalized.charAt(idoff);
}
}
return new_text;
}
Gracias a todos
, uso esta versión y digo por qué (porque me faltan esas explicaciones al principio, así que trato de ayudar al siguiente lector si es tan aburrido como yo ...)
Observación: Quería una solución eficiente, así que:
- solo una compilación de expresiones regulares (si es necesario)
- solo una cadena de escaneo para cada cadena
- una forma eficiente de encontrar los caracteres traducidos, etc ...
Mi versión es:
(no hay un nuevo truco técnico en su interior, solo algunos seleccionados + explicaciones de por qué)
makeSortString = (function() {
var translate_re = /[¹²³áàâãäåaaaÀÁÂÃÄÅAAAÆccç©CCÇÐÐèéê?ëeeeeeÈÊË?EEEEE€gGiìíîïìiiiÌÍÎÏ?ÌIIIlLnnñNNÑòóôõöoooøÒÓÔÕÖOOOØŒr®Ršs?ߊS?ùúûüuuuuÙÚÛÜUUUUýÿÝŸžzzŽZZ]/g;
var translate = {
"¹":"1","²":"2","³":"3","á":"a","à":"a","â":"a","ã":"a","ä":"a","å":"a","a":"a","a":"a","a":"a","À":"a","Á":"a","Â":"a","Ã":"a","Ä":"a","Å":"a","A":"a","A":"a",
"A":"a","Æ":"a","c":"c","c":"c","ç":"c","©":"c","C":"c","C":"c","Ç":"c","Ð":"d","Ð":"d","è":"e","é":"e","ê":"e","?":"e","ë":"e","e":"e","e":"e","e":"e","e":"e",
"e":"e","È":"e","Ê":"e","Ë":"e","?":"e","E":"e","E":"e","E":"e","E":"e","E":"e","€":"e","g":"g","G":"g","i":"i","ì":"i","í":"i","î":"i","ï":"i","ì":"i","i":"i",
"i":"i","i":"i","Ì":"i","Í":"i","Î":"i","Ï":"i","?":"i","Ì":"i","I":"i","I":"i","I":"i","l":"l","L":"l","n":"n","n":"n","ñ":"n","N":"n","N":"n","Ñ":"n","ò":"o",
"ó":"o","ô":"o","õ":"o","ö":"o","o":"o","o":"o","o":"o","ø":"o","Ò":"o","Ó":"o","Ô":"o","Õ":"o","Ö":"o","O":"o","O":"o","O":"o","Ø":"o","Œ":"o","r":"r","®":"r",
"R":"r","š":"s","s":"s","?":"s","ß":"s","Š":"s","S":"s","?":"s","ù":"u","ú":"u","û":"u","ü":"u","u":"u","u":"u","u":"u","u":"u","Ù":"u","Ú":"u","Û":"u","Ü":"u",
"U":"u","U":"u","U":"u","U":"u","ý":"y","ÿ":"y","Ý":"y","Ÿ":"y","ž":"z","z":"z","z":"z","Ž":"z","Z":"z","Z":"z"
};
return function(s) {
return(s.replace(translate_re, function(match){return translate[match];}) );
}
})();
y lo uso de esta manera:
var without_accents = makeSortString("wïthêüÄTrèsBïgüeAk100t");
// I let you guess the result,
// no I was kidding you : I give you the result : witheuatresbigueak100t
Comentarios:
- La instrucción interna se realiza una vez (después de, makeSortString! = Undefined)
- La función () {...} se almacena una vez en makeSortString, por lo que los objetos "grandes" translate_re y translate se almacenan una vez
- Cuando llama a makeSortString (''algo''), llama directamente a la función interna que llama solo a su lugar (...): es eficiente
- s.replace usa regexp (la sintaxis especial de var translate_re = .... es de hecho equivalente a var translate_re = new RegExp ("[¹ .... Z]", "g"); pero la compilación de la regexp se realiza de una vez por todas, y la exploración de la cadena s se realiza una para una llamada de la función (no para todos los caracteres, ya que estaría en un bucle)
- Para cada carácter encontrado, la función de llamadas (coincidencia) donde la coincidencia del parámetro contiene el carácter encontrado, y llama al correspondiente carácter traducido (traducir [coincidencia])
- La traducción [coincidencia] es probablemente también eficiente, ya que el objeto de traducción javascript probablemente se implementa mediante javascript con un hashtab o algo equivalente y permite que el programa encuentre el carácter traducido casi directamente y no, por ejemplo, a través de un bucle en una matriz de todos los caracteres para encontrar la correcta (que sería terriblemente ineficiente).
He billy el código de http://jsfiddle.net/billybraga/UHmnf/ (de su post ) en este: http://jsfiddle.net/infralabs/dJX58/
Corrigí la transcripción de los caracteres ſ y ß y también añadí coversion de estos: Þþ , Ðð , Ŋŋ , IJij , Œœ .
El fragmento modificado está abajo:
var defaultDiacriticsRemovalMap = [{
''base'': "A",
''letters'': /(A|Ⓐ|A|À|Á|Â|Ầ|Ấ|Ẫ|Ẩ|Ã|Ā|Ă|Ằ|Ắ|Ẵ|Ẳ|Ȧ|Ǡ|Ä|Ǟ|Ả|Å|Ǻ|Ǎ|Ȁ|Ȃ|Ạ|Ậ|Ặ|Ḁ|Ą|Ⱥ|Ɐ|[/u0041/u24B6/uFF21/u00C0/u00C1/u00C2/u1EA6/u1EA4/u1EAA/u1EA8/u00C3/u0100/u0102/u1EB0/u1EAE/u1EB4/u1EB2/u0226/u01E0/u00C4/u01DE/u1EA2/u00C5/u01FA/u01CD/u0200/u0202/u1EA0/u1EAC/u1EB6/u1E00/u0104/u023A/u2C6F])/g
}, {
''base'': "AA",
''letters'': /(Ꜳ|[/uA732])/g
}, {
''base'': "AE",
''letters'': /(Æ|Ǽ|Ǣ|[/u00C6/u01FC/u01E2])/g
}, {
''base'': "AO",
''letters'': /(Ꜵ|[/uA734])/g
}, {
''base'': "AU",
''letters'': /(Ꜷ|[/uA736])/g
}, {
''base'': "AV",
''letters'': /(Ꜹ|Ꜻ|[/uA738/uA73A])/g
}, {
''base'': "AY",
''letters'': /(Ꜽ|[/uA73C])/g
}, {
''base'': "B",
''letters'': /(B|Ⓑ|B|Ḃ|Ḅ|Ḇ|Ƀ|Ƃ|Ɓ|[/u0042/u24B7/uFF22/u1E02/u1E04/u1E06/u0243/u0182/u0181])/g
}, {
''base'': "C",
''letters'': /(C|Ⓒ|C|Ć|Ĉ|Ċ|Č|Ç|Ḉ|Ƈ|Ȼ|Ꜿ|[/u0043/u24B8/uFF23/u0106/u0108/u010A/u010C/u00C7/u1E08/u0187/u023B/uA73E])/g
}, {
''base'': "D",
''letters'': /(D|Ⓓ|D|Ḋ|Ď|Ḍ|Ḑ|Ḓ|Ḏ|Đ|Ƌ|Ɗ|Ɖ|Ꝺ|Ð|[/u0044/u24B9/uFF24/u1E0A/u010E/u1E0C/u1E10/u1E12/u1E0E/u0110/u018B/u018A/u0189/uA779/u00D0])/g
}, {
''base'': "DZ",
''letters'': /(DZ|DŽ|[/u01F1/u01C4])/g
}, {
''base'': "Dz",
''letters'': /(Dz|Dž|[/u01F2/u01C5])/g
}, {
''base'': "E",
''letters'': /(E|Ⓔ|E|È|É|Ê|Ề|Ế|Ễ|Ể|Ẽ|Ē|Ḕ|Ḗ|Ĕ|Ė|Ë|Ẻ|Ě|Ȅ|Ȇ|Ẹ|Ệ|Ȩ|Ḝ|Ę|Ḙ|Ḛ|Ɛ|Ǝ|[/u0045/u24BA/uFF25/u00C8/u00C9/u00CA/u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/u1EE0/u1EDE/u1EE2/u1ECC/u1ED8/u01EA/u01EC/u00D8/u01FE/u0186/u019F/uA74A/uA74C])/g
}, {
''base'': "OE",
''letters'': /(Œ|[/u0152])/g
}, {
''base'': "OI",
''letters'': /(Ƣ|[/u01A2])/g
}, {
''base'': "OO",
''letters'': /(Ꝏ|[/uA74E])/g
}, {
''base'': "OU",
''letters'': /(Ȣ|[/u0222])/g
}, {
''base'': "P",
''letters'': /(P|Ⓟ|P|Ṕ|Ṗ|Ƥ|Ᵽ|Ꝑ|Ꝓ|Ꝕ|[/u0050/u24C5/uFF30/u1E54/u1E56/u01A4/u2C63/uA750/uA752/uA754])/g
}, {
''base'': "Q",
''letters'': /(Q|Ⓠ|Q|Ꝗ|Ꝙ|Ɋ|[/u0051/u24C6/uFF31/uA756/uA758/u024A])/g
}, {
''base'': "R",
''letters'': /(R|Ⓡ|R|Ŕ|Ṙ|Ř|Ȑ|Ȓ|Ṛ|Ṝ|Ŗ|Ṟ|Ɍ|Ɽ|Ꝛ|Ꞧ|Ꞃ|[/u0052/u24C7/uFF32/u0154/u1E58/u0158/u0210/u0212/u1E5A/u1E5C/u0156/u1E5E/u024C/u2C64/uA75A/uA7A6/uA782])/g
}, {
''base'': "S",
''letters'': /(S|Ⓢ|S|ẞ|Ś|Ṥ|Ŝ|Ṡ|Š|Ṧ|Ṣ|Ṩ|Ș|Ş|Ȿ|Ꞩ|Ꞅ|[/u0053/u24C8/uFF33/u1E9E/u015A/u1E64/u015C/u1E60/u0160/u1E66/u1E62/u1E68/u0218/u015E/u2C7E/uA7A8/uA784])/g
}, {
''base'': "T",
''letters'': /(T|Ⓣ|T|Ṫ|Ť|Ṭ|Ț|Ţ|Ṱ|Ṯ|Ŧ|Ƭ|Ʈ|Ⱦ|Ꞇ|[/u0054/u24C9/uFF34/u1E6A/u0164/u1E6C/u021A/u0162/u1E70/u1E6E/u0166/u01AC/u01AE/u023E/uA786])/g
}, {
''base'': "TH",
''letters'': /(Þ|[/u00DE])/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/u24CF/uFF3A/u0179/u1E90/u017B/u017D/u1E92/u1E94/u01B5/u0224/u2C7F/u2C6B/uA762])/g
}, {
''base'': "a",
''letters'': /(a|ⓐ|a|ẚ|à|á|â|ầ|ấ|ẫ|ẩ|ã|ā|ă|ằ|ắ|ẵ|ẳ|ȧ|ǡ|ä|ǟ|ả|å|ǻ|ǎ|ȁ|ȃ|ạ|ậ|ặ|ḁ|ą|ⱥ|ɐ|[/u0061/u24D0/uFF41/u1E9A/u00E0/u00E1/u00E2/u1EA7/u1EA5/u1EAB/u1EA9/u00E3/u0101/u0103/u1EB1/u1EAF/u1EB5/u1EB3/u0227/u01E1/u00E4/u01DF/u1EA3/u00E5/u01FB/u01CE/u0201/u0203/u1EA1/u1EAD/u1EB7/u1E01/u0105/u2C65/u0250])/g
}, {
''base'': "aa",
''letters'': /(ꜳ|[/uA733])/g
}, {
''base'': "ae",
''letters'': /(æ|ǽ|ǣ|[/u00E6/u01FD/u01E3])/g
}, {
''base'': "ao",
''letters'': /(ꜵ|[/uA735])/g
}, {
''base'': "au",
''letters'': /(ꜷ|[/uA737])/g
}, {
''base'': "av",
''letters'': /(ꜹ|ꜻ|[/uA739/uA73B])/g
}, {
''base'': "ay",
''letters'': /(ꜽ|[/uA73D])/g
}, {
''base'': "b",
''letters'': /(b|ⓑ|b|ḃ|ḅ|ḇ|ƀ|ƃ|ɓ|[/u0062/u24D1/uFF42/u1E03/u1E05/u1E07/u0180/u0183/u0253])/g
}, {
''base'': "c",
''letters'': /(c|ⓒ|c|ć|ĉ|ċ|č|ç|ḉ|ƈ|ȼ|ꜿ|ↄ|[/u0063/u24D2/uFF43/u0107/u0109/u010B/u010D/u00E7/u1E09/u0188/u023C/uA73F/u2184])/g
}, {
''base'': "d",
''letters'': /(d|ⓓ|d|ḋ|ď|ḍ|ḑ|ḓ|ḏ|đ|ƌ|ɖ|ɗ|ꝺ|ð|[/u0064/u24D3/uFF44/u1E0B/u010F/u1E0D/u1E11/u1E13/u1E0F/u0111/u018C/u0256/u0257/uA77A/u00F0])/g
}, {
''base'': "dz",
''letters'': /(dz|dž|[/u01F3/u01C6])/g
}, {
''base'': "e",
''letters'': /(e|ⓔ|e|è|é|ê|ề|ế|ễ|ể|ẽ|ē|ḕ|ḗ|ĕ|ė|ë|ẻ|ě|ȅ|ȇ|ẹ|ệ|ȩ|ḝ|ę|ḙ|ḛ|ɇ|ɛ|ǝ|[/u0065/u24D4/uFF45/u00E8/u00E9/u00EA/u1EC1/u1EBF/u1EC5/u1EC3/u1EBD/u0113/u1E15/u1E17/u0115/u0117/u00EB/u1EBB/u011B/u0205/u0207/u1EB9/u1EC7/u0229/u1E1D/u0119/u1E19/u1E1B/u0247/u025B/u01DD])/g
}, {
''base'': "f",
''letters'': /(f|ⓕ|f|ḟ|ƒ|ꝼ|[/u0066/u24D5/uFF46/u1E1F/u0192/uA77C])/g
}, {
''base'': "g",
''letters'': /(g|ⓖ|g|ǵ|ĝ|ḡ|ğ|ġ|ǧ|ģ|ǥ|ɠ|ꞡ|ᵹ|ꝿ|[/u0067/u24D6/uFF47/u01F5/u011D/u1E21/u011F/u0121/u01E7/u0123/u01E5/u0260/uA7A1/u1D79/uA77F])/g
}, {
''base'': "h",
''letters'': /(h|ⓗ|h|ĥ|ḣ|ḧ|ȟ|ḥ|ḩ|ḫ|ẖ|ħ|ⱨ|ⱶ|ɥ|[/u0068/u24D7/uFF48/u0125/u1E23/u1E27/u021F/u1E25/u1E29/u1E2B/u1E96/u0127/u2C68/u2C76/u0265])/g
}, {
''base'': "hv",
''letters'': /(ƕ|[/u0195])/g
}, {
''base'': "i",
''letters'': /(i|ⓘ|i|ì|í|î|ĩ|ī|ĭ|ï|ḯ|ỉ|ǐ|ȉ|ȋ|ị|į|ḭ|ɨ|ı|[/u0069/u24D8/uFF49/u00EC/u00ED/u00EE/u0129/u012B/u012D/u00EF/u1E2F/u1EC9/u01D0/u0209/u020B/u1ECB/u012F/u1E2D/u0268/u0131])/g
}, {
''base'': "ij",
''letters'': /(ij|[/u0133])/g
}, {
''base'': "j",
''letters'': /(j|ⓙ|j|ĵ|ǰ|ɉ|[/u006A/u24D9/uFF4A/u0135/u01F0/u0249])/g
}, {
''base'': "k",
''letters'': /(k|ⓚ|k|ḱ|ǩ|ḳ|ķ|ḵ|ƙ|ⱪ|ꝁ|ꝃ|ꝅ|ꞣ|[/u006B/u24DA/uFF4B/u1E31/u01E9/u1E33/u0137/u1E35/u0199/u2C6A/uA741/uA743/uA745/uA7A3])/g
}, {
''base'': "l",
''letters'': /(l|ⓛ|l|ŀ|ĺ|ľ|ḷ|ḹ|ļ|ḽ|ḻ|ł|ƚ|ɫ|ⱡ|ꝉ|ꞁ|ꝇ|[/u006C/u24DB/uFF4C/u0140/u013A/u013E/u1E37/u1E39/u013C/u1E3D/u1E3B/u0142/u019A/u026B/u2C61/uA749/uA781/uA747])/g
}, {
''base'': "lj",
''letters'': /(lj|[/u01C9])/g
}, {
''base'': "m",
''letters'': /(m|ⓜ|m|ḿ|ṁ|ṃ|ɱ|ɯ|[/u006D/u24DC/uFF4D/u1E3F/u1E41/u1E43/u0271/u026F])/g
}, {
''base'': "n",
''letters'': /(n|ⓝ|n|ǹ|ń|ñ|ṅ|ň|ṇ|ņ|ṋ|ṉ|ƞ|ɲ|ʼn|ꞑ|ꞥ|ŋ|[/u006E/u24DD/uFF4E/u01F9/u0144/u00F1/u1E45/u0148/u1E47/u0146/u1E4B/u1E49/u019E/u0272/u0149/uA791/uA7A5/u014B])/g
}, {
''base'': "nj",
''letters'': /(nj|[/u01CC])/g
}, {
''base'': "o",
''letters'': /(o|ⓞ|o|ò|ó|ô|ồ|ố|ỗ|ổ|õ|ṍ|ȭ|ṏ|ō|ṑ|ṓ|ŏ|ȯ|ȱ|ö|ȫ|ỏ|ő|ǒ|ȍ|ȏ|ơ|ờ|ớ|ỡ|ở|ợ|ọ|ộ|ǫ|ǭ|ø|ǿ|ɔ|ꝋ|ꝍ|ɵ|[/u006F/u24DE/uFF4F/u00F2/u00F3/u00F4/u1ED3/u1ED1/u1ED7/u1ED5/u00F5/u1E4D/u022D/u1E4F/u014D/u1E51/u1E53/u014F/u022F/u0231/u00F6/u022B/u1ECF/u0151/u01D2/u020D/u020F/u01A1/u1EDD/u1EDB/u1EE1/u1EDF/u1EE3/u1ECD/u1ED9/u01EB/u01ED/u00F8/u01FF/u0254/uA74B/uA74D/u0275])/g
}, {
''base'': "oe",
''letters'': /(œ|[/u0153])/g
}, {
''base'': "oi",
''letters'': /(ƣ|[/u01A3])/g
}, {
''base'': "ou",
''letters'': /(ȣ|[/u0223])/g
}, {
''base'': "oo",
''letters'': /(ꝏ|[/uA74F])/g
}, {
''base'': "p",
''letters'': /(p|ⓟ|p|ṕ|ṗ|ƥ|ᵽ|ꝑ|ꝓ|ꝕ|[/u0070/u24DF/uFF50/u1E55/u1E57/u01A5/u1D7D/uA751/uA753/uA755])/g
}, {
''base'': "q",
''letters'': /(q|ⓠ|q|ɋ|ꝗ|ꝙ|[/u0071/u24E0/uFF51/u024B/uA757/uA759])/g
}, {
''base'': "r",
''letters'': /(r|ⓡ|r|ŕ|ṙ|ř|ȑ|ȓ|ṛ|ṝ|ŗ|ṟ|ɍ|ɽ|ꝛ|ꞧ|ꞃ|[/u0072/u24E1/uFF52/u0155/u1E59/u0159/u0211/u0213/u1E5B/u1E5D/u0157/u1E5F/u024D/u027D/uA75B/uA7A7/uA783])/g
}, {
''base'': "s",
''letters'': /(s|ⓢ|s|ś|ṥ|ŝ|ṡ|š|ṧ|ṣ|ṩ|ș|ş|ȿ|ꞩ|ꞅ|ẛ|ſ|[/u0073/u24E2/uFF53/u015B/u1E65/u015D/u1E61/u0161/u1E67/u1E63/u1E69/u0219/u015F/u023F/uA7A9/uA785/u1E9B/u017F])/g
}, {
''base'': "ss",
''letters'': /(ß|[/u00DF])/g
}, {
''base'': "t",
''letters'': /(t|ⓣ|t|ṫ|ẗ|ť|ṭ|ț|ţ|ṱ|ṯ|ŧ|ƭ|ʈ|ⱦ|ꞇ|[/u0074/u24E3/uFF54/u1E6B/u1E97/u0165/u1E6D/u021B/u0163/u1E71/u1E6F/u0167/u01AD/u0288/u2C66/uA787])/g
}, {
''base'': "th",
''letters'': /(þ|[/u00FE])/g
}, {
''base'': "tz",
''letters'': /(ꜩ|[/uA729])/g
}, {
''base'': "u",
''letters'': /(u|ⓤ|u|ù|ú|û|ũ|ṹ|ū|ṻ|ŭ|ü|ǜ|ǘ|ǖ|ǚ|ủ|ů|ű|ǔ|ȕ|ȗ|ư|ừ|ứ|ữ|ử|ự|ụ|ṳ|ų|ṷ|ṵ|ʉ|[/u0075/u24E4/uFF55/u00F9/u00FA/u00FB/u0169/u1E79/u016B/u1E7B/u016D/u00FC/u01DC/u01D8/u01D6/u01DA/u1EE7/u016F/u0171/u01D4/u0215/u0217/u01B0/u1EEB/u1EE9/u1EEF/u1EED/u1EF1/u1EE5/u1E73/u0173/u1E77/u1E75/u0289])/g
}, {
''base'': "v",
''letters'': /(v|ⓥ|v|ṽ|ṿ|ʋ|ꝟ|ʌ|[/u0076/u24E5/uFF56/u1E7D/u1E7F/u028B/uA75F/u028C])/g
}, {
''base'': "vy",
''letters'': /(ꝡ|[/uA761])/g
}, {
''base'': "w",
''letters'': /(w|ⓦ|w|ẁ|ẃ|ŵ|ẇ|ẅ|ẘ|ẉ|ⱳ|[/u0077/u24E6/uFF57/u1E81/u1E83/u0175/u1E87/u1E85/u1E98/u1E89/u2C73])/g
}, {
''base'': "x",
''letters'': /(x|ⓧ|x|ẋ|ẍ|[/u0078/u24E7/uFF58/u1E8B/u1E8D])/g
}, {
''base'': "y",
''letters'': /(y|ⓨ|y|ỳ|ý|ŷ|ỹ|ȳ|ẏ|ÿ|ỷ|ẙ|ỵ|ƴ|ɏ|ỿ|[/u0079/u24E8/uFF59/u1EF3/u00FD/u0177/u1EF9/u0233/u1E8F/u00FF/u1EF7/u1E99/u1EF5/u01B4/u024F/u1EFF])/g
}, {
''base'': "z",
''letters'': /(z|ⓩ|z|ź|ẑ|ż|ž|ẓ|ẕ|ƶ|ȥ|ɀ|ⱬ|ꝣ|[/u007A/u24E9/uFF5A/u017A/u1E91/u017C/u017E/u1E93/u1E95/u01B6/u0225/u0240/u2C6C/uA763])/g
}];
Pase una función definida por el usuario al Array.sort()
método, y en esta función definida por el usuario uselocaleCompare()
function myCompareFunction(a, b) {
return a.localeCompare(b);
}
var values = ["pêches", "épinards", "tomates", "fraises"];
// WRONG: ["fraises", "pêches", "tomates", "épinards"]
values.sort();
// **GOOD**: ["épinards", "fraises", "pêches", "tomates"]
values.sort(myCompareFunction);
Proporcioné esta respuesta para una pregunta similar. Se basa en el reemplazo rápido de búsqueda en la tabla para los caracteres seleccionados (latín 1 + 2), uno por uno (no es posible cambiar ü en alemán), pero funciona bien para la "normalización" básica a ASCII de 7 bits.
TAB_00C0 = "AAAAAAACEEEEIIII" +
"DNOOOOO*OUUUUYIs" +
"aaaaaaaceeeeiiii" +
"?nooooo/ouuuuy?y" +
"AaAaAaCcCcCcCcDd" +
"DdEeEeEeEeEeGgGg" +
"GgGgHhHhIiIiIiIi" +
"IiJjJjKkkLlLlLlL" +
"lLlNnNnNnnNnOoOo" +
"OoOoRrRrRrSsSsSs" +
"SsTtTtTtUuUuUuUu" +
"UuUuWwYyYZzZzZzF";
function stripDiacritics(source) {
var result = source.split('''');
for (var i = 0; i < result.length; i++) {
var c = source.charCodeAt(i);
if (c >= 0x00c0 && c <= 0x017f) {
result[i] = String.fromCharCode(TAB_00C0.charCodeAt(c - 0x00c0));
} else if (c > 127) {
result[i] = ''?'';
}
}
return result.join('''');
}
stripDiacritics("Šupa, čo? ľšťčžýæøåℌð")
Cualquier otro carácter se convierte a?, Es decir, el resultado es definitivamente ASCII de 7 bits. No regex, no magic, simple char array trabajo.
Puede crear expresiones regulares de varias maneras. Usando el nuevo RegExp
-constructor:
var re = new RegExp("[a-z]", "ig") //(string pattern, string modifiers)
O usando la notación literal de expresiones regulares:
var re = /[a-z]/ig; // /pattern/modifiers
Has mezclado los dos.
Puedes usar el _.deburr
método de la biblioteca de Lodash.
Está disponible como un paquete NPM independiente lodash.deburr
o como parte del lodash
paquete.
let myStringWithAccent = ''Mon café est plein de caféïne'';
let myStringWithoutAccent = deburr(myStringWithAccent);
El resultado será: "Mon cafe est plein de cafeine"
Sé que es "hacer trampa" para hacer esto en el lado del servidor, pero la semana pasada tuve una tarea similar en Javascript y presenté un simple servlet de Java y eliminé los acentos en Java . Fue muy rapido :)
Si está abierto a usar una biblioteca, puede usar String.js latinize: latinise()
Todo lo anterior no funciona con caracteres descompuestos como se usa en Mac OS. Para eliminar los diacríticos en ese caso es más sencillo:
r = r.replace(new RegExp(/[/u0300-/u036f]/g),"")
vea el comentario de Olivier Miakinen en: https://groups.google.com/d/msg/fr.comp.lang.regexp/6IGJTbedGTM/G0sB2kAsR34J (publicado en francés)
Una solución que parece ser mucho más rápida según la prueba dada: http://jsperf.com/diacritics/9
function removeDiacritics(str) {
return str.replace(/[^A-Za-z0-9/s]+/g, function(a){
return diacriticsMap[a] || a;
});
}
removeDiacritics(teste);
Ejemplo de trabajo: http://jsbin.com/sovorute/1/edit
Razonamiento : una razón por la que esto es mucho más rápido es porque solo iteramos a través de los caracteres especiales, seleccionados por el patrón de expresiones regulares negado. El más rápido de las pruebas ( Iteración de cadena sin entrada ) itera 1001 en el texto dado, lo que significa cada carácter . Esta itera solo 35 veces y produce el mismo resultado . Tenga en cuenta que esto solo reemplazará lo que se indica en el mapa.
Artículo clásico sobre el tema: http://alistapart.com/article/accent-folding-for-auto-complete
Crédito : http://semplicewebsites.com/removing-accents-javascript , también proporciona un buen mapa de caracteres.
Usé el método latinise latinise() string.js , que te permite hacerlo así:
var output = S(input).latinise().toString();
$scope.legal_name = $sanitize($scope.legal_name);
console.log("Name before function...",$scope.legal_name);
var str = "";
for(var i=0; i < $scope.legal_name.length; i++) {
var charName = $scope.legal_name.charAt(i);
if((charName == ''&'') && ($scope.legal_name.charAt(i + 1) == ''#'')){
var count = 0;
var subString = "";
while(true) {
if(($scope.legal_name.charCodeAt(i + 2 + count) > 47) && ($scope.legal_name.charCodeAt(i + 1 + count) < 58 )) {
subString = subString + $scope.legal_name.charAt(i + 2 + count);
count++;
} else {
if(subString.length > 0) {
var value = parseInt(subString);
str = str + String.fromCharCode(value);
i = i + 1 + count;
break;
}
}
}
} else {
str = str + charName;
}
}
$scope.legal_name = str;
console.log("Name After function...",str);
function removeAccents(strAccents){
strAccents = strAccents.split('''');
strAccentsOut = new Array();
strAccentsLen = strAccents.length;
var accents = ''ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž'';
var accentsOut = [''A'',''A'',''A'',''A'',''A'',''A'',''a'',''a'',''a'',''a'',''a'',''a'',''O'',''O'',''O'',''O'',''O'',''O'',''O'',''o'',''o'',''o'',''o'',''o'',''o'',''E'',''E'',''E'',''E'',''e'',''e'',''e'',''e'',''e'',''C'',''c'',''D'',''I'',''I'',''I'',''I'',''i'',''i'',''i'',''i'',''U'',''U'',''U'',''U'',''u'',''u'',''u'',''u'',''N'',''n'',''S'',''s'',''Y'',''y'',''y'',''Z'',''z''];
for (var y = 0; y < strAccentsLen; y++) {
if (accents.indexOf(strAccents[y]) != -1) {
strAccentsOut[y] = accentsOut[accents.indexOf(strAccents[y])];
}
else
strAccentsOut[y] = strAccents[y];
}
strAccentsOut = strAccentsOut.join('''');
return strAccentsOut;
}