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

167
Vistas
Javascript: match() is returning non-matching text after the pattern matched substring

I'm trying to extract all of the hyperlinks out of a large HTML file using javascript in the nodejs command line console.

match() is extracting the hyperlinks, but also returning non matching text after it.

For example:

Text before the link <a href="http:\\angst.org/frustration/pita1.html class=\"outlink\">PITA 1</a> the text after the link.`

Sample result:

<a href="http:\\angst.org/frustration/pita1.html class=\"outlink\">PITA 1</a> the text after the link.

Interestingly, when I took one of textArray lines/strings, wrapped it in back ticks and set it to a variable the code below worked fine. I would get just what I want only:

<a href="http:\\angst.org/frustration/pita1.html class=\"outlink\">PITA 1</a>

This is the javascript I am using:

// is an html file, input code removed for clarity of this example
var text;  

// Split the html file into lines
const textArray = text.split("\n");

// Regexp pattern to match the links
var p = /<a href=\"http:\/\/angst.org\/frustration\/(.+)\.html\" class=\"outlink\">(.+)<\/a>/;

// Extract and output all of the hyperlinks
for (let i = 0; i < textArray.length; i++) {
    resultArray = textArray[i].match(p);
    console.log(resultArray[0]);
}
about 4 years ago · Juan Pablo Isaza
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