Replace all VNese letters with the corresponding English accents

Published on
1 mins read
6 views

Replace all VNese letters with the corresponding English accents

let toPlainEnglish = (str) => {
  str = str.replace(/à|á|||ã|â||||||ă|||||/g, "a");
  str = str.replace(/è|é||||ê||ế|||/g, "e");
  str = str.replace(/ì|í|||ĩ/g, "i");
  str = str.replace(/ò|ó|||õ|ô||||||ơ|||||/g, "o");
  str = str.replace(/ù|ú|||ũ|ư|||||/g, "u");
  str = str.replace(/|ý|||/g, "y");
  str = str.replace(/đ/g, "d");
  str = str.replace(/À|Á|||Ã|Â||||||Ă|||||/g, "A");
  str = str.replace(/È|É||||Ê|||||/g, "E");
  str = str.replace(/Ì|Í|||Ĩ/g, "I");
  str = str.replace(/Ò|Ó|||Õ|Ô||||||Ơ|||||/g, "O");
  str = str.replace(/Ù|Ú|||Ũ|Ư|||||/g, "U");
  str = str.replace(/|Ý|||/g, "Y");
  str = str.replace(/Đ/g, "D");

  // OPTIONAL - Remove special chars
  // str = str.replace(/[^a-zA-Z0-9 \s]/g, "")

  return str;
};

console.log(toPlainEnglish("Tuấn Anh")); // => "Tuan Anh"