Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda