Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9322181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:01:32+00:00 2026-06-19T04:01:32+00:00

Fighting with regex…. I’m using this to find pieces of HTML-string between certain elements:

  • 0

Fighting with regex….

I’m using this to find pieces of HTML-string between certain elements:

 for (i = 0; i < 2; i += 1) {
   target = block[i];   // like BODY or HEAD
   regex = RegExp('<' + target + '>(.)+</' + target + '>');
   // in case string passed includes breaks/spaces
   data = data.replace(/(\r\n|\n|\r)/gm,"").replace(/\s+/g," ")
             .match(regex);
   entry = data[0].replace(/<!-- [\s\S]*? -->/g, '');
   console.log(entry);
 }

While this works fine, it returns something like this:

<head>....everthing I want ....</head>

Question:
How do I need to modifiy the regex, so that I can still specifiy the element whose content I need, but which returns only the content and not content & tokens (like <head></head>).

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:01:33+00:00Added an answer on June 19, 2026 at 4:01 am

    Use the first matching group instead of the whole match.

    regex = RegExp('<' + target + '>(.+)</' + target + '>');
    

    and then…

    entry = data[1].replace(/<!-- [\s\S]*? -->/g, '');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been fighting this problem with the help of a RegEx cheat sheet,
I'm fighting this error and i can't find a way of fixing it... Take
I'm fighting too long on this regex now. The split should use blank as
I'm fighting with this issue for a long time now and I can't find
Still fighting with templates. In this example, despite the fact that is copied straight
I'm fighting against an oddity (I think) of the offsetWidth property. this is the
I have been fighting with this problem for hours. I can't seem to figure
I have been fighting this for a whole night... I'm trying to use Python
I've been fighting with this for a couple of days and there doesn't seem
I've been fighting this all day. Inside my styles.xml file I have color information

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.