extracting text

Discussion in 'Ruby' started by Dan, Jul 11, 2003.

  1. Dan

    Dan Guest

    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
     
    Dan, Jul 11, 2003
    #1
    1. Advertising

  2. Dan

    Dan Guest

    thank you
    "Tim Hunter" <> wrote in message
    news:...
    > 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>
    >
    > On Fri, 11 Jul 2003 07:46:44 -0400, "Dan" <>
    > wrote:
    >
    > >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
    > >

    >
     
    Dan, Jul 11, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kunal
    Replies:
    0
    Views:
    483
    kunal
    Oct 15, 2005
  2. Bubbles
    Replies:
    0
    Views:
    452
    Bubbles
    Mar 3, 2004
  3. kunal
    Replies:
    0
    Views:
    364
    kunal
    Oct 15, 2005
  4. =?Utf-8?B?S2V2aW4gSw==?=
    Replies:
    2
    Views:
    2,919
    =?Utf-8?B?S2V2aW4gSw==?=
    Apr 6, 2006
  5. John Davison
    Replies:
    1
    Views:
    597
    Hal Rosser
    Jul 7, 2004
Loading...

Share This Page