From: Alexandre Mutel Date: 2009-11-19T23:53:35+09:00 Subject: Re: How to strip ruby comments in a ruby line of code? Aldric Giacomoni wrote: > Actually, no, because regexps are greedy by default, so it'll go to the > very last '#' it finds. > The other solution you got is more elegant, though.. :) hum, not sure the greedy is helping there: line = "line = \"\#{args}\"" => "line = \"\#{args}\"" string = line.match(/^.*#/).to_s[0...-1] => "line = " Expecting is : line = "#{args}" In order to strip comments using regexp, you need to handle string escape. -- Posted via http://www.ruby-forum.com/.