Last active
April 13, 2020 07:57
-
-
Save hta218/49218b2ae6c411b82f1c96a7a2f8434b to your computer and use it in GitHub Desktop.
Replace all VNese letters with the corresponding English accents and remove all special characters (`!@#$%^&*()+=)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const 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") | |
// Remove special chars | |
str = str.replace(/[^a-zA-Z0-9 \s]/g, "") | |
return str | |
} | |
const text = "abcxyz123456 Huỳnh Tuấn Anh !@#~~%%^&*()_)_+=-6969" | |
console.log(toPlainEnglish(text)) // Expected: "abcxyz123456 Huynh Tuan Anh 6969" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment