Simple regex question

Discussion in 'Ruby' started by Todd, Oct 25, 2005.

  1. Todd

    Todd Guest

    Hello,

    Sorry to waste your time with this, but I'm new to regular expressions.
    I, simply want to grab the text between two html tags:

    various characters and whitespace <span id="title">Dog Eggs</title>
    various characters and whitespace

    I want a regex that notices the "title" id and grabs Dog Eggs for me.
    I have one that works, but it's really kludgey.

    Thanks,
    Todd
     
    Todd, Oct 25, 2005
    #1
    1. Advertising

  2. Todd wrote:
    > Hello,
    >
    > Sorry to waste your time with this, but I'm new to regular expressions.
    > I, simply want to grab the text between two html tags:
    >
    > various characters and whitespace <span id="title">Dog Eggs</title>
    > various characters and whitespace
    >
    > I want a regex that notices the "title" id and grabs Dog Eggs for me.
    > I have one that works, but it's really kludgey.
    >
    > Thanks,
    > Todd


    DATA.read.scan( /id="title">(.*?)</m ) { |s|
    puts s
    }

    __END__
    characters and whitespace <span id="title">Platypus Eggs</title>
    various characters and whitespace
    <span id="title">Bird
    Teeth</title>
     
    William James, Oct 25, 2005
    #2
    1. Advertising

  3. Todd

    Todd Guest

    Perfect, thanks! Didn't know about String.scan.

    Todd
     
    Todd, Oct 25, 2005
    #3
  4. On 25/10/05, Todd <> wrote:
    > Hello,
    >
    > Sorry to waste your time with this, but I'm new to regular expressions.
    > I, simply want to grab the text between two html tags:
    >
    > various characters and whitespace <span id=3D"title">Dog Eggs</title>
    > various characters and whitespace
    >
    > I want a regex that notices the "title" id and grabs Dog Eggs for me.
    > I have one that works, but it's really kludgey.
    >
    > Thanks,
    > Todd
    >


    irb(main):001:0> text =3D %(<span id=3D"title">Dog Eggs</title>)
    =3D> "<span id=3D\"title\">Dog Eggs</title>"
    irb(main):002:0> text[%r(<span id=3D"title">(.*?)</title>), 1]
    =3D> "Dog Eggs"

    I really like this interface.

    regards,

    Brian

    >
    >



    --
    http://ruby.brian-schroeder.de/

    Stringed instrument chords: http://chordlist.brian-schroeder.de/
     
    Brian Schröder, Oct 25, 2005
    #4
    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. Saad Malik
    Replies:
    5
    Views:
    399
    John C. Bollinger
    May 2, 2005
  2. John Salerno

    a simple regex question

    John Salerno, Apr 1, 2006, in forum: Python
    Replies:
    6
    Views:
    321
    Paddy
    Apr 2, 2006
  3. johnny

    Simple Python REGEX Question

    johnny, May 11, 2007, in forum: Python
    Replies:
    4
    Views:
    422
    James T. Dennis
    May 12, 2007
  4. Replies:
    3
    Views:
    821
    Reedick, Andrew
    Jul 1, 2008
  5. Sam Kong
    Replies:
    8
    Views:
    128
    Csaba Henk
    Mar 25, 2005
Loading...

Share This Page