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]);
}