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

140
Visualizações
How can I use regex to get matches on each side of the equal sign for the string (test1)=(tes=)t2)

I need to capture two matches between an equal sign: (test1)=(test2) such that match1 = test1 and match2 = test2. So far I have been able to use /\([\s\S\)\(]*?\)/gmi which mostly works UNLESS there is an additional close paren on either side of the equal sign, ie: (test1)=(te)st2).

What regex could I create that would allow me to successfully wind up with two matches given the below:

"(test1)=(tes=)t2)".match( /\([\s\S\)\(]*?\)/gmi ) === ["test1", "tes=)t2"]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For the examples in the question and if supported using lookarounds, you can assert that the closing parenthesis can not contain = or ) to the right.

Note that you can omit the /m flag as there are no anchors in the pattern, and you can also omit the /i flag as the pattern does not specifically matches upper or lowercase characters.

let regex = /(?<=\().*?(?=\)(?![^\s=)]))/g;
let str = "(test1)=(tes=)t2)";
console.log(str.match(regex));

Or using a capture group without a lookbehind assertion:

let regex = /\((.*?)\)(?![^\s=])/g;
let str = "(test1)=(tes=)t2)";
const result = Array.from(str.matchAll(regex), m => m[1]);
console.log(JSON.stringify(result) === JSON.stringify(["test1", "tes=)t2"]));

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