Is there a way to apply the method replace
to text in Unicode in general (Arabic is a concern here)? In the example below, while replacing the whole word works fine in the English text, it does not detect and as a result replaces the Arabic word. I added u
as a flag to enable Unicode parsing, but that didn't help. In the Arabic example below, the word ุงููุฌูู
should be replaced, but not ูุงููุฌูู
, but this does not happen.
<!DOCTYPE html>
<html>
<body>
<p>Click to replace...</p>
<button onclick="myFunction()">replace</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = "ุงูุดู
ุณ ูุงููู
ุฑ ูุงููุฌูู
ุ ุซู
ุงููุฌูู
ูุงูููุงุฑ";
var rep = 'ุงููุฌูู
';
var repWith = 'ุงูููู';
var result = str.replace(new RegExp("\\b"+rep+"\\b", "ug"), repWith);
document.getElementById("demo").innerHTML = result;
}
</script>
</body>
</html>
And whatever solution you propose, save it using variables, as you see in the above code (the variable rep
above), since they replace the words that are requested, passed through function calls.
UPDATE. , .