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

  • Home
  • SEARCH
  • 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 8190967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:48:13+00:00 2026-06-07T03:48:13+00:00

Going crazy trying to figure this out for the past 2 hours. I have

  • 0

Going crazy trying to figure this out for the past 2 hours. I have this html returned as a string from an AJAX request:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Preview</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="author" content="Connected Ventures LLC. Copyright 1999-2010." />
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.ui.js"></script>
    <script type="text/javascript" src="js/article.js"></script>
    <link href="/css/global.css" rel="stylesheet" type="text/css" />
    <link href="/css/article.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    html, body { background: #fff; color: #000; }
    </style>
</head>
<body class="the_article">
        <p>s</p></body>
</html>

I need to get the content in between the body tags. I already tried this which was suggested in another SO question on parsing html via jQuery:

$(ajax_response).find('body.the_article').html();

Didn’t work. Even after adding:

dataType: 'html'

as an ajax request parameter. Then I tried to parse it using regex:

ajax_response.match(/<body class="the_article">.*?<\/body>/); 

it just alerts null. Any idea how I can get the body content?

  • 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-07T03:48:16+00:00Added an answer on June 7, 2026 at 3:48 am

    Your REGEX is failing because the string is multi-line, and the . wildcard matches all characters except whitespace characters, so the newline after, say, the opening body tag and the body’s content, breaks the pattern.

    Use [\s\S] instead of . (literally, allow non-space and space characters)

    /<body class="the_article">[\s\S]*?<\/body>/
    

    [EDIT] – in response to the comment, to capture the body content exclusive of its tags, capture the contents as a sub-group:

    var body = response.match(/<body class="the_article">([\s\S]*?)(?=<\/body>)/);
    console.log(body[1]); //body content, not including tag
    

    Note also we specify the closing body tag as a look-ahead, since we don’t need to match that at all, merely anchor to it. (JS doesn’t support look-behinds, short of simulations like the one I wrote, so we have no choice but to capture the opening body tag).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going crazy trying to figure this out. I have tried everything I
I am going crazy trying to figure this out without success. I have a
I am going crazy trying to figure this out. I am trying to make
I have been going crazy trying to figure out how to query a php
I've been going crazy trying to figure out why this is happening. The problem
I'm going crazy trying to figure out this error message that has no obvious
i've been trying to figure this out and i have absolutely no clue why
Im going crazy trying to figure out how to get the value of the
I have been going crazy trying to get the selected option to align left
This is driving me crazy as I cannot figure out what in the world

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.