Simple regex question

T

Todd

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
 
W

William James

Todd said:
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>
 
B

Brian Schröder

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
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top