Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / July 2007



Tip: Looking for answers? Try searching our database.

regex to return just body of HTML responseText

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mel - 30 Jul 2007 17:37 GMT
I just need the content between <body> and </body> of a message

How can i do this from http_request.responseText string ?

thanks
Peter Michaux - 30 Jul 2007 17:41 GMT
> I just need the content between <body> and </body> of a message

You need it or want to set it?

> How can i do this from http_request.responseText string ?

If you need it in the http_request.reponseText string (ie that string
is/has some JavaScript) then just use document.body.innerHTML.

To set it

document.body.innerHTML = http_request.responseText;

Peter
Peter Michaux - 30 Jul 2007 17:43 GMT
> > I just need the content between <body> and </body> of a message
>
[quoted text clipped - 10 lines]
>
> Peter

I didn't see the subject line of your post at first. Won't this work?

/<body>(.)</body>/

Peter
Duncan Booth - 30 Jul 2007 18:03 GMT
>> > I just need the content between <body> and </body> of a message
>>
> I didn't see the subject line of your post at first. Won't this work?
>
> /<body>(.)</body>/

You mean apart from the unescaped slash in the middle of the regex, the
fact that a dot only matches 1 character, and also that a dot won't match a
newline?

This would probably work most of the time:

   /<body[^>]*>((?:.|\n)*)<\/body>/
Peter Michaux - 30 Jul 2007 18:13 GMT
On Jul 30, 10:03 am, Duncan Booth <duncan.bo...@invalid.invalid>
wrote:

> >> > I just need the content between <body> and </body> of a message
>
[quoted text clipped - 5 lines]
> fact that a dot only matches 1 character, and also that a dot won't match a
> newline?

Of course :) I suppose I was trying to figure out what is abnormal or
tricky about this RegExp question.

Peter

> This would probably work most of the time:
>
>     /<body[^>]*>((?:.|\n)*)<\/body>/
Thomas 'PointedEars' Lahn - 31 Jul 2007 10:54 GMT
> [...] Won't this work?
>
> /<body>(.)</body>/

If the infix slash would be escaped, this would work if the body element
was a one-liner with one-non-whitespace-character content  :)

You were looking for

  req.responseText.match(/<body(?:\s+(?:.|\n)*?)?>((.|\n)*)<\/body>/)[1]

or a backwards-compatible substitute like

  req.responseText.match(/<body(\s+[^>]*)?>((.|\n)*)<\/body>/)[2]

PointedEars
Signature

var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    &&
    navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

Thomas 'PointedEars' Lahn - 31 Jul 2007 11:00 GMT
> [...] Won't this work?
>
> /<body>(.)</body>/

If the infix slash would be escaped, this would work if the body element
was a one-liner with one-non-whitespace-character content  :)

You were looking for

  req.responseText.match(/<body(?:\s+(?:.|\s)*?)?>((.|\s)*)<\/body>/)[1]

or a backwards-compatible substitute like

  req.responseText.match(/<body(\s+[^>]*)?>((.|\s)*)<\/body>/)[2]

PointedEars
Signature

Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not the
best source of advice on designing systems that use javascript.
  -- Richard Cornford, <f806at$ail$1$8300dec7@news.demon.co.uk>

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.