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

165
Visualizações
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 à 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