Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!