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

171
Views
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
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!