Search code examples
javascriptdiacriticsiso-8859-1

Javascript replace diacritic characters in iso-8859-1


I'm trying to replace some diacritics (accent) caracters in plain javascript. but I have no clue on what to do. My problem is that we use the charset iso-8859-1. If we'd use the utf-8, it would have been easier. I'm trying to make someting like this script here (that works in UTF-8 encoding).

Can anyone help me on this one ? If I could just have the syntax for a replace from "é" to "e" I'd do the rest just fine. I tried some things with \xE9 but not beeing very familiar with regular expressions, I couldn't make it work.


Solution

  • Finally I found this regex syntax :

            Recherche = Recherche.replace(/À|Á|Â|Ã|Ä|Å/g, "A")
                                 .replace(/à|á|â|ã|ä|å/g, "a")
                                 .replace(/Ò|Ó|Ô|Õ|Õ|Ö|Ø/g, "O")
                                 .replace(/ò|ó|ô|õ|ö|ø/g, "o")
                                 .replace(/È|É|Ê|Ë/g, "E")
                                 .replace(/è|é|ê|ë/g, "e")
                                 .replace(/Ç|ç/g, "c")
                                 .replace(/Ì|Í|Î|Ï/g, "I")
                                 .replace(/ì|í|î|ï/g, "i")
                                 .replace(/Ù|Ú|Û|Ü/g, "U")
                                 .replace(/ù|ú|û|ü/g, "u");