From: Phillip Gawlowski Date: 2009-12-27T12:40:29+09:00 Subject: Re: How to truncate the spaces in the front of a line On 27.12.2009 04:22, Milo Luo wrote: > Hi, guys > I am new to Ruby. Do you have any idea to truncate or remove the space > in the front of a line? irb(main):001:0> " spaces in front".gsub /^ +/,"" => "spaces in front" irb(main):002:0> RUBY_VERSION => "1.8.6" irb(main):003:0> Translation: String#gsub applies the regexp given as first argument to a given String, and replaces the matches with the second argument. The regexp "^ +" (the // notation is one of the many ways to tell Ruby we are using a regexp) means "At the beginning of the line ("^"), find any spaces(" "), and then stop ("+")". More or less, anyway (I'm not a Regexp guru). ;) -- Phillip Gawlowski