Skip to content

Instantly share code, notes, and snippets.

@blackestwhite
Last active October 25, 2022 11:42
Show Gist options
  • Save blackestwhite/01a18aedb5380545b9f5ab9c3a90732b to your computer and use it in GitHub Desktop.
Save blackestwhite/01a18aedb5380545b9f5ab9c3a90732b to your computer and use it in GitHub Desktop.
English to Persian, Persian to English digit conversion, JavaScript RegEx
const ToPersian = str => str.replace(/\d/g, idx => '۰۱۲۳۴۵۶۷۸۹'[idx])
const ToEnglish = str => str.replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment