From: Robert Klemme Date: 2010-03-30T16:12:50+09:00 Subject: Re: return number of spaces at the beginning of a line 2010/3/30 Jesse B. : > How would I find the number of spaces at the beginning of a line before > the occurrance of the first non-space character? spaces = str[/\A\s*/].length > Would the best method be to use a regular expression that covers all > non-space characters and get the index of the first occurrance of that? I'd rather use the approach above because it always works (i.e. even with empty strings). Your approach could be done like this: spaces = /\S/ =~ s as has been show already. But this fails for empty strings. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/