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

135
Vistas
How can i bold the word before colon only if colon exists in line by regular expression

These four lines are store as an array of objects in ptr

["NF: (Chuckling)","EM: And we taught not very long. Ms. Fox (ph) took my place. I met Ethan and we","were married in February (Chuckling). I had taught from September to February--","NF: Wow!"]

I am trying to show these in jsx line by line and to bold every word before colon if in some line there is no colon then it should not bold the whole line as showing below, it only bolds word before colon if there is colon in line

NF: (Chuckling)

EM: And we taught not very long. Ms. Fox (ph) took my place. I met Ethan and we

were married in February (Chuckling). I had taught from September to February--

NF: Wow!

<p key={k}>{ptr.split(/(?=:)/).map((x,i)=> i===0 ? <b key={i}>{x}</b> : x) } </p>)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to check if the array you are processing inside .map() contains more than one element (to check if split actually occurred and the string was split into at least two chunks).

Add the third argument to .map() and add the && arr.length>1 check:

<p key={k}>{ptr.split(/(?=:)/).map((x,i,arr)=> i===0 && arr.length>1 ? <b key={i}>{x}</b> : x) } </p>)
about 4 years ago · Juan Pablo Isaza Denunciar
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