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

86
Visualizações
How to make RegExps ignore some tags

I want to make my regular expression ignore if there are any tags between two characters. I thought of getting the child node list and defining some strings that corresponding start and finish tags of that nodes but I couldn't solve how to make my regular expression ignore that tags.

For example, I've listed the insert tags and made this array

let tags = ["<div class='cl'>","</div>","<span class='sp'>","</span>"]

The string in which I want to search my regular expression

let str = "The people <div class='cl'>in StackOverflow <span class='sp'> are very helpful.</span></div>"

And I want to find "people in StackOverflow" in this text to get the start and finish indexes. How can I do that?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If the regex matches both the tags and what's not in a tag.
Then you can capture and keep what's not in a tag.

/<[^>]+>|([^<>]+)/g

const str = "The people <div class='cl'>in StackOverflow <span class='sp'> are very helpful.</span></div>"

let re = /<[^>]+>|([^<>]+)/g;

let result = str.replace(re,'$1');

console.log(result);

let positions = [];
while (m = re.exec(str)) {
  if(m[1]) positions.push([m.index, re.lastIndex])
}
console.log(positions);

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