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

312
Views
How to get the substring from between two [ ] braces in a string in javascript or jquery

My string looks like this street no [12]

I need to extract the 12 alone from the string.

How do I get the substring between two [ ] in javascript or jquery?

find the substring between first matching [] brackets

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

0

I noted that your requirements changed in a comment below the previous answer, to fix that issue you can change the regex adding ? so it will capture the least possible matches.

const myString = "street no [12][22]"
const match = myString.match(/\[(.+?)\]/);
const myNumber = match && match[1];
console.log(myNumber);

Or, you can just capture digits if that works better for your needs

const myString = "street no [12][22]"
const match = myString.match(/\[(\d+)\]/);
const myNumber = match && match[1];
console.log(myNumber);

about 4 years ago · Juan Pablo Isaza Report

0

You can use a regular expression for this:

const myString = "street no [12]"
const match = myString.match(/\[(.+)\]/);
const myNumber = match && match[1];
console.log(myNumber);

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!