Skip to content

Instantly share code, notes, and snippets.

@smarteist
Last active June 14, 2021 07:22
Show Gist options
  • Select an option

  • Save smarteist/36161d2512fa3f17bf5bc271de0ff9d7 to your computer and use it in GitHub Desktop.

Select an option

Save smarteist/36161d2512fa3f17bf5bc271de0ff9d7 to your computer and use it in GitHub Desktop.
Arabic and Persian Characters to general form
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<textarea rows="20" cols="150" id="input"></textarea>
<br><br><br>
<label>
new line to space
<input type="checkbox" id="remove-newline">
</label>
<button id="format">Format</button>
<br><br><br>
<textarea rows="20" cols="150" id="output"></textarea>
<script>
document.getElementById("format").addEventListener("click", function (e) {
var input = document.getElementById("input").value;
if (document.getElementById("remove-newline").checked) {
input = input.replace(/(\r\n|\n|\r)/gm, " ");
}
input = input.replace(/([ﺂﺁ])/gm, "آ");
input = input.replace(/([ﺎﺍ])/gm, "ا");
input = input.replace(/([ﺄﺃ])/gm, "أ");
input = input.replace(/([ﺑﺒﺐﺏ])/gm, "ب");
input = input.replace(/([ﭘﭙﭗﭖ])/gm, "پ");
input = input.replace(/([ﺑﺒﺐﺏ])/gm, "ب");
input = input.replace(/([ﺗﺘﺖﺕ])/gm, "ت");
input = input.replace(/([ﺛﺜﺚﺙ])/gm, "ث");
input = input.replace(/([ﺟﺠﺞﺝ])/gm, "ج");
input = input.replace(/([ﺣﺤﺢﺡ])/gm, "ح");
input = input.replace(/([ﺧﺨﺦﺥ])/gm, "خ");
input = input.replace(/([ﭼﭽﭻﭺ])/gm, "چ");
input = input.replace(/([ﺪﺩ])/gm, "د");
input = input.replace(/([ﺬﺫ])/gm, "ذ");
input = input.replace(/([ﺮﺭ])/gm, "ر");
input = input.replace(/([ﺰﺯ])/gm, "ز");
input = input.replace(/([ﮋﮊ])/gm, "ژ");
input = input.replace(/([ﺳﺴﺲﺱ])/gm, "س");
input = input.replace(/([ﺷﺸﺶﺵ])/gm, "ش");
input = input.replace(/([ﺻﺼﺺﺹ])/gm, "ص");
input = input.replace(/([ﺿﻀﺾﺽ])/gm, "ض");
input = input.replace(/([ﻃﻄﻂﻁ])/gm, "ط");
input = input.replace(/([ﻇﻈﻆﻅ])/gm, "ظ");
input = input.replace(/([ﻋﻌﻊﻉ])/gm, "ع");
input = input.replace(/([ﻏﻐﻎﻍ])/gm, "غ");
input = input.replace(/([ﻓﻔﻒﻑ])/gm, "ف");
input = input.replace(/([ﻗﻘﻖﻕ])/gm, "ق");
input = input.replace(/([ﻛﻜﻚﻙكﮑﮐﮏﮎ])/gm, "ک");
input = input.replace(/([ﮔﮕﮓﮒ])/gm, "گ");
input = input.replace(/([ﻟﻠﻞﻝ])/gm, "ل");
input = input.replace(/([ﻣﻤﻢﻡ])/gm, "م");
input = input.replace(/([ﻧﻨﻦﻥ])/gm, "ن");
input = input.replace(/([ﻫﻬﻪﻩﺔﺓ])/gm, "ه");
input = input.replace(/([ﻮﻭ])/gm, "و");
input = input.replace(/([ﻳﻴﻲﻱيﻯﻰى])/gm, "ی");
input = input.replace(/([ﺌﺋﺊﺉ])/gm, "ئ");
input = input.replace(/([ﻶﻵﻷﻸﻺﻻﻼﻹ])/gm, "لا");
input = input.replace(/([ـ])/gm, "");
input = input.replace(/([‌])/gm, " ");
document.getElementById("output").innerHTML = input;
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment