From: Aldric Giacomoni Date: 2009-11-19T23:44:06+09:00 Subject: Re: How to strip ruby comments in a ruby line of code? Alexandre Mutel wrote: > Aldric Giacomoni wrote: >> I'm still only learning regular expressions (I'll do another shameless >> plug for rubular.com here), but you could do this: >> string = string.match(/^.*#).to_s[0...-1] >> >> Yes, it's a poor solution, but should you have nothing else, it'll do. > > the problem with your solution is that this line of code will remove > valid code : > myvar_s = "#{myvar}" > > The problem is to handle correctly string escape sequence... it's > possible, but it requires much more work... I just want to know if > someone else did this?! 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.. :) -- Posted via http://www.ruby-forum.com/.