Re: Problem with reqular expression


#1

pls ignore
slow mail; i thought no one was answering. argh… better wait longer…

-----Original Message-----

From: Peña, Botp [mailto:removed_email_address@domain.invalid]

Sent: Tuesday, May 23, 2006 6:50 PM

To: ruby-talk ML

Subject: Re: Problem with reqular expression

fr Ilyas:

# I have this string:

# Color1 R=144 G=248 B=255

# Need regular expression for get R,G,B

# How I can simplify it:

# lines.gsub!(/Color1 R=(\d+) G=(\d+) B=(\d+)/) {

# puts $1

# puts $2

# puts $3

# }

irb(main):026:0> s = “Color1 R=144 G=248 B=255”

=> “Color1 R=144 G=248 B=255”

irb(main):030:0>

r,g,b=(/R=(\d+)\s+G=(\d+)\s+B=(\d+)/).match(s).captures

=> [“144”, “248”, “255”]

irb(main):031:0> r

=> “144”

irb(main):032:0> g

=> “248”

irb(main):033:0> b

=> “255”