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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    465
    John C. Bollinger
    May 2, 2005
  2. John Salerno

    a simple regex question

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

    Simple Python REGEX Question

    johnny, May 11, 2007, in forum: Python
    Replies:
    4
    Views:
    517
    James T. Dennis
    May 12, 2007
  4. Replies:
    3
    Views:
    1,112
    Reedick, Andrew
    Jul 1, 2008
  5. Sam Kong
    Replies:
    8
    Views:
    261
    Csaba Henk
    Mar 25, 2005
  6. Peter Bailey

    Simple regex question.

    Peter Bailey, Jun 26, 2009, in forum: Ruby
    Replies:
    6
    Views:
    206
    Robert Klemme
    Jun 26, 2009
  7. Geometric Patterns

    Very simple regex question

    Geometric Patterns, Nov 13, 2010, in forum: Ruby
    Replies:
    2
    Views:
    206
    Hassan Schroeder
    Nov 13, 2010
  8. frans abels

    RegEx Woes! Please Help, Simple Question

    frans abels, May 1, 2005, in forum: Perl Misc
    Replies:
    13
    Views:
    351
    Joonas Timo Taavetti Kekoni
    May 2, 2005
Loading...