regex help needed

M

Mel

I need to strip everything from a file except what is between <body>
and </body>

thanks for your help
 
E

Evertjan.

Mel wrote on 18 mei 2007 in comp.lang.javascript:
I need to strip everything from a file except what is between <body>
and </body>

regex has no access to a file content, only to a string.

When you have transferred that content to a string s, try:

s = s.replace(/^[\s\S]*?<body>([\s\S]*)?<\/body>[\s\S]*$/i,'$1');

The availability of the non-greedy "?"
depends on the version of the JS engine.
 

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

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,428
Latest member
RosalieQui

Latest Threads

Top