Skip to content

Instantly share code, notes, and snippets.

@hertz1
Last active September 29, 2022 16:21
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save hertz1/686e90aeffb4d166ab1a to your computer and use it in GitHub Desktop.
Save hertz1/686e90aeffb4d166ab1a to your computer and use it in GitHub Desktop.
Função simples e eficiente para remover todos os tipos de acentos da língua portuguesa.
/**
* Remove acentos de strings
* @param {String} string acentuada
* @return {String} string sem acento
*/
var map={"â":"a","Â":"A","à":"a","À":"A","á":"a","Á":"A","ã":"a","Ã":"A","ê":"e","Ê":"E","è":"e","È":"E","é":"e","É":"E","î":"i","Î":"I","ì":"i","Ì":"I","í":"i","Í":"I","õ":"o","Õ":"O","ô":"o","Ô":"O","ò":"o","Ò":"O","ó":"o","Ó":"O","ü":"u","Ü":"U","û":"u","Û":"U","ú":"u","Ú":"U","ù":"u","Ù":"U","ç":"c","Ç":"C"};
function removerAcentos(s){ return s.replace(/[\W\[\] ]/g,function(a){return map[a]||a}) };
@leovargasdev
Copy link

Valeu aí @yuritoledo e @alefhsousa funcionou perfeitamente!

@gufigueiredo esse método não removeu os caracteres, por incrível que pareça kk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment