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

176
Vistas
Regex to capture first group in brackets before a match. Here: hexcolor within {my text}{#F00}

I need to convert custom syntax into a <span> with a color attribute.

Example input:

First {text with link}{https://www.stackoverflow.com/}. Followed by {colored text}{#85144B}.

For now I used in Javascript:

line = line.replace(/\{(.*?)\}\{(#[0-9,A-F,a-f]{3}|#[0-9,A-F,a-f]{6})\}/g, '<span style="color:$2">$1</span>');

which matches/replaces if there is only one occurence of those brackets {}.

However, with the example above it matches all the other brackets too (greedy?):

regex101 A

regex101 B

Being still a Regex rookie I cannot figure out how to ONLY match the first group (enclosed in brackets) before the hexcolor block.

I tried lookahead assertion and negative lookahead assertion but failed.

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