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

246
Views
How would I select a value of a string that is in parentheses?

I want to select the contents of the second pair of parentheses in this string

"Hello my name is (john) (doe)."

How would I go about doing that? In addition, if there were an unknown number of pairs of parentheses, how would I be able to select the contents of the last one?

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

0

Here's a couple of possibilities. The first uses a regex to grab text between the last pair of parentheses (asserted using a lookahead that asserts there are no more opening parentheses after the last closing one), the second uses split, first on an opening parenthesis, grabbing the last value and then splitting that on a closing parenthesis and taking the first part of the result:

const str = "Hello my name is (john) (doe)."

result = str.match(/(?<=\()[^)]*(?=\)[^(]*$)/)[0]
console.log(result)

result = str.split('(').pop().split(')')[0]
console.log(result)

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!