From: "Jesse B." Date: 2010-03-30T19:41:53+09:00 Subject: Re: return number of spaces at the beginning of a line This second post with the "spaces only" fix seems to meet all the needs of what I was looking for. I love that this got 9 replies in the middle of the night. thanks everyone for your help. Robert Klemme wrote: > 2010/3/30 Josh Cheek : >> On Mon, Mar 29, 2010 at 8:41 PM, Jesse B. wrote: > >> Hi, a quick appraisal of the issues with previous solutions. > >> Each of these count non-space whitespaces (ie " \t hello" would be 3 instead >> of 1 ) >> s.index(%r{\S}) >> >> str[/\A\s*/].length >> >> s =~ /(\s*)/ >> $1.length > > Oh, that's easily fixed: just replace \s with ' ' e.g. s[\A */].length > (still my favorite). I thought general whitespace was sought after. > > Kind regards > > robert -- Posted via http://www.ruby-forum.com/.