parsing HTML results

J

John Raines

Hello-

I am trying to parse HTML results which look like this:

<html>
<body>
<span class=aaa>this is a test</span><span class=bbb>testing
again</span><span class=aaa>test number 3</span>
</body>
</html>

All the <span> are on one line.

In this particular case, I want to match all the <span class=aaa> so that my
results would look like:

this is a test
test number 3

I was fairly successful with a regex like /<span class=aaa>(.*)</span>/ but
I could only get the first result.

Is there an easy way to match <span class=aaa>*</span> and return the
contents within the tag? And to either insert the results into an array, or
have the ability to loop through the results?

Thanks
 
J

Jürgen Exner

John said:
I am trying to parse HTML results which look like this:
[...]
This has been discussed a gazillion of times.
Is there an easy way to match <span class=aaa>*</span> and return the
contents within the tag? And to either insert the results into an
array, or have the ability to loop through the results?

Absolutely. The best way to do it is as described in the FAQ: just use a
parser to parse HTML.

jue
 

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
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top