Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda