Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda