Ilyas
(Ilyas)
23 May 2006 10:19
1
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
}
···
--
Posted via http://www.ruby-forum.com/ .
Erm... "/Color1 R=(\d+) G=(\d+) B=(\d+)/" seems to me about
as simple as you can get. I do wonder why you're using an in-place
substitution, though.
Joost.
···
On Tue, May 23, 2006 at 07:19:50PM +0900, 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
}
Regg_Mr
(Regg Mr)
23 May 2006 10:41
4
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.
···
--
Posted via http://www.ruby-forum.com/\ .
Ilyas
(Ilyas)
23 May 2006 12:20
5
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/\ .