extracting text

D

Dan

I have a HTML table which I would like to extract text inside a <TD>. For an
example
<TD class=12>Some text</TD>

I can write a code that detects the beginning of TD...
print line ~= "<TD class12>"

But how do I make it stop at </TD>. In the code above, I just want to print
"Some text"

thanks
 
D

Dan

thank you
Tim Hunter said:
Here's one answer to your question. Watch out, almost any change to
the input will break it.

irb(main):012:0> s = "<TD class=12>Some text</TD>"
"<TD class=12>Some text</TD>"
irb(main):013:0> m = %r{<TD [^>]+>([^<]+)</TD>}.match(s)
#<MatchData:0x276f978>
irb(main):014:0> p m[1]
"Some text"
nil
irb(main):015:0>

I have a HTML table which I would like to extract text inside a <TD>. For an
example
<TD class=12>Some text</TD>

I can write a code that detects the beginning of TD...
print line ~= "<TD class12>"

But how do I make it stop at </TD>. In the code above, I just want to print
"Some text"

thanks
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top