[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Regular expression problem

sujeet kumar

6/11/2005 9:44:00 PM

hi
I want to sepearte a pattern from a string using regular expression
and scan. String is
str = "<font color=#008000>www.<b>ruby</b>central.com/ - 4k - </font><nobr>a"
patttern is the part of string that is in between "#008000> " and "</font>"
for above str pattern is www.<b>ruby</b>central.com/ - 4k -

How to do this.
i tried like
str = "<font color=#008000>www.<b>ruby</b>central.com/ - 4k - </font><nobr>a"
temp.scan(/(#008000>)(^(</font>))*(</font>)/) {|w| print "#{w} \n" }

But this gives error
Reg.rb:4: warning: Object#type is deprecated; use Object#class

How to do this.
Thanks
Sujeet


3 Answers

Nikolai Weibull

6/11/2005 10:09:00 PM

0

sujeet kumar wrote:

> str = "<font color=#008000>www.<b>ruby</b>central.com/ - 4k - </font><nobr>a"
> temp.scan(/(#008000>)(^(</font>))*(</font>)/) {|w| print "#{w} \n" }

You can use the following regular expression (which isnâ??t very flexible):

/#008000>(.*?)</font>/

Thatâ??ll slurp up anything from the end of the <font> to the beginning of
the </font>, so to speak.

> But this gives error
> Reg.rb:4: warning: Object#type is deprecated; use Object#class

Thatâ??s a warning, and itâ??s unrelated to your matching,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


simonced

6/12/2005 7:11:00 AM

0

Hi,

What about this one ?
/<font.*?>(.*?)<\/font>/

Sorry, I didn't test it.

Nikolai Weibull

6/12/2005 12:25:00 PM

0

simonced wrote:

> What about this one ?
> /<font.*?>(.*?)<\/font>/

Sure, but he didnâ??t want to match just any <font>â?¦</font>,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}