inputArray = ["z","d"];
inputArray = ["د","ذ"];
function trans(stri){
inputArray.forEach((value, i) => {
var next = i + 1;
a1 = inputArray[i];
a2 = outputArray[i];
regex = new XRegExp(a1, "g");
stri = XRegExp.replace(stri, regex, a2, ["all"])
return stri;
});
}
console.log(trans("dzzd"))
I wanna translate from latin characters to arabic characters, how to use {{Arabic}}?, and I Very new to RegExp or even XRegExp, So how basically i do it? Also I'm very very sorry if im Lack of Experience..
Expected Output = "دذذد"
You can do all the replacements in one pass, making an alternation out of
inputArrayand using a replacement function to return the appropriate character fromoutputArrayon a match:Note that if
frommight contain overlapping values (for exampleabanda) you need to sortfromandtoby the length of the strings infromdescending before using them. You can do that with this code:This ensures that the regex always matches the longest sequence by preference (since it will come first in the alternation).
You could either insert into the
transfunction, for example:or use it on
inputArrayandoutputArraybefore you calltrans: