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

310
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
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