From: Ilyas Date: 2006-05-23T21:20:12+09:00 Subject: Re: Problem with reqular expression Regg Mr wrote: > Ilyas wrote: >> 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 >> } > > > lines.gsub!(/R=(\d+) G=(\d+) B=(\d+)/) {puts $1; puts $2; puts $3} > > =>144 > =>248 > =>255 > > You didn't use semi-colons within your block. It's all what I wanted: def get_color(rgb_string, color) @R, @G, @B = 0, 0, 0 @R, @G, @B = Regexp.new(color + '\s+R=(\d+)\s+G=(\d+)\s+B=(\d+)'). match(rgb_string).captures sprintf("#%x%x%x", @R, @G, @B) end Thanks for Pena, Botp because your idea -- Posted via http://www.ruby-forum.com/.