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

156
Views
Regex replace strings matching pattern with multiple charercters

I have a string like this

const str = "Today is going to be @[City Temp](city-temp) in @[City Name](city-name)"

I want the output to be in handlebars syntax eg

const str = "Today is going to be {{city-temp}} in {{city-name}}"

I am having trouble trying to match this pattern.

I can see that if I do

str.replace(/[()]/g,"")

I get the string without the brackets.

But I can't work out how to search for the whole pattern something like the below where I find anything starting with @[ and ending with ), I don't want to just start with @ by itself as there may be times in the string I don't want to remove the @ where it is not followed by a [

/[\@\[A-Za-z0-9\](A-Za-z0-9-)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use

str = str.replace(/@\[[^\][]*]\(([^()]*)\)/g, "{{$1}}")

See the regex demo. Details:

  • @\[ - a @[ string
  • [^\][]* - zero or more chars other than [ and ]
  • ]\( - a ]( string
  • ([^()]*) - Group 1 ($1): any zero or more chars other than ( and )
  • \) - a ) char.

See the JavaScript demo:

const str = "Today is going to be @[City Temp](city-temp) in @[City Name](city-name)"
console.log(str.replace(/@\[[^\][]*]\(([^()]*)\)/g, "{{$1}}"))

about 4 years ago · Juan Pablo Isaza Report
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!