Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
javascript replace unicode word using regex

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!