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

167
Views
Get pre-header from HTML using regex

I would like to extract the pre-header from a HTML using regex. The HTML looks like this:

<!DOCTYPE html><html>
<head>...</head>
<body dir="ltr" style="padding: 0; margin: 0"><div style="display: none; max-height: 0px; overflow: hidden;">This is my preheader &mdash; </div><table cellspacing="0" cellpadding="0" style="width: 100%">
...
</body></html>

This means that the pre-header is placed directly after the <body> start tag as a <div> element. Furthermore, it has the display: none style class. So I think it would be best to extract the first element after the <body> start tag, then check if it's a <div> with corresponding style class (otherwise no pre-header maintained) and if so, extract the text from it ignoring escapes and stuff like &mdash;.

I would like to implement this in JavaScript. It would help me very much to 1) know the regex to extract the first element after the <body> start tag and 2) extract the plain text value from the <div> element.

Thank you very much for assistance in advance.

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!