Need help with parsing. Please....

M

Mel

I have:

<head><title>JUNK</title></head><body >HELLO</body>

i need to strip off all tags <> and end up with the content "HELLO".

can someone show me how ?

thanks a whole bunch
 
E

Evertjan.

Mel wrote on 20 jun 2006 in comp.lang.javascript:
I have:

<head><title>JUNK</title></head><body >HELLO</body>

i need to strip off all tags <> and end up with the content "HELLO".

Impossible, you need a string to manipulate.

s = '<head><title>JUNK</title></head><body >HELLO</body>'

in the simplest form:

result = s.replace(/.*/,'HELLO')

Because if you strip of all tags like this:

result = s.replace(/<[^>]*>/g,'')

result would be: 'JUNKHELLO'

==============

Perhaps you only want the body content?

result = s.replace(/(.*?<body[^>]*>)|(<\/body>)/g,'')
 
M

Mel

Evertjan. said:
Mel wrote on 20 jun 2006 in comp.lang.javascript:
I have:

<head><title>JUNK</title></head><body >HELLO</body>

i need to strip off all tags <> and end up with the content "HELLO".

Impossible, you need a string to manipulate.

s = '<head><title>JUNK</title></head><body >HELLO</body>'

in the simplest form:

result = s.replace(/.*/,'HELLO')

Because if you strip of all tags like this:

result = s.replace(/<[^>]*>/g,'')

result would be: 'JUNKHELLO'

==============

Perhaps you only want the body content?

result = s.replace(/(.*?<body[^>]*>)|(<\/body>)/g,'')



result = s.replace(/(.*?<body[^>]*>)|(<\/body>)/g,'')

also returns the title with my string. YOU are right, all i am looking
for is the string between the body tags with leading and trailing
blanks, new lines etc removed.

Can you please help ?
 
N

Noah Sussman

Mel, you said you have:
<head><title>JUNK</title></head><body >HELLO</body>

Assuming that this is the structure of the document in the browser;
then "document.body.innerHTML" would evalutate to "HELLO".

Not sure if that solves your problem.
 
E

Evertjan.

Mel wrote on 20 jun 2006 in comp.lang.javascript:
s = '<head><title>JUNK</title></head><body >HELLO</body>'
result = s.replace(/(.*?<body[^>]*>)|(<\/body>)/g,'')

result = s.replace(/(.*?<body[^>]*>)|(<\/body>)/g,'')

also returns the title with my string.

It does not, at least on IE6.

Using some old js, perhaps,
that does not know the non-greedy concept of '?'
YOU are right, all i am looking
for is the string between the body tags with leading and trailing
blanks, new lines etc removed.

Perhaps you better try to learn the ins and outs of regex?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help please 8
Troubles with Fullpage / please help 0
Help with some CSS 2
Need help again please 19
Need help with stripe payment 0
Please Help? 0
Please help 1
I dont get this. Please help me!! 2

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top