Skip to content

Instantly share code, notes, and snippets.

@sajaddp
Last active August 12, 2022 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajaddp/cfde6e99a26b6177fa353d4a597f7230 to your computer and use it in GitHub Desktop.
Save sajaddp/cfde6e99a26b6177fa353d4a597f7230 to your computer and use it in GitHub Desktop.
Convert Persian and Arabic digits of a string to English using JavaScript
const converter = (text) => text.replace(/[٠-٩۰-۹]/g,a=>a.charCodeAt(0)&15);
console.log(converter("۳٣۶٦۵any٥۵٤۶32٠۰"));
// Output: "33665any55453200"
//[Reference](https://stackoverflow.com/a/63133882/6390834)
const converter = (text) => text.replace(/[٠-٩۰-۹]/g,a=>a.charCodeAt(0)&15);
console.log(converter("۳٣۶٦۵any٥۵٤۶32٠۰"));
// Output: "33665any55453200"

Reference

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