I want to replace a word in Unicode string in JavaScript using regex and facing a problem.
While this piece of code (with ASCII) works fine:
var str= 'blue Mr Blue bluevan has a blue house qblueb and a bluecar blue';
var rep= "\\b(blue)\\b";
var re = new RegExp(rep,"gu");
var res = str.replace(re, " <span>$1</span>");
// res= '<span>blue</span> Mr Blue bluevan has a <span>blue</span> house qblueb and a bluecar <span>blue</span>'
But this piece of code fails:
var str= 'মৌলবী গিরিশচন্দ্র দেনসেনকে ভার দেন';
var rep= "\\b(দেন)\\b";
var re = new RegExp(rep,"gu");
var res = str.replace(re, " <span>$1</span>");
// res (actual)= 'মৌলবী গিরিশচন্দ্র দেনসেনকে ভার দেন'
// res (expected)= 'মৌলবী গিরিশচন্দ্র দেনসেনকে ভার <span>দেন</span>'
/* var rep= "(দেন)"; replaces all the occurrences of দেন successfully */
Can anyone give me an idea why this is happening? Thanks in advance.