From: Peter Vandenabeele Date: 2012-02-09T18:05:02+09:00 Subject: Re: How to catch first occurence of [a-z] --002354470c5c9503d304b8844e38 Content-Type: text/plain; charset=UTF-8 On Thu, Feb 9, 2012 at 6:07 AM, Mario Trento wrote: > Hi, > > Yes, I'm in learning mode and trying to see how I can change very first > occurrence of alpha char in string (or list), in my example first char > in string could be \s or \t, so I need to check for this. > It's multi line string, so I broke up it in list elements = line, and > now thinking how to process it. > What string function I can use? > > > list = multi_linestring.split(/\n/) > ##then iterate thru each line { |ll| ......????} > > Thanks all > Writing an example is shorter than a long explanation. As your learning experience, try to understand in detail how/why this works ... $ irb 1.9.3p0 :001 > " \t \t first line \nsecond line".split(/\n/).each do |line| 1.9.3p0 :002 > line.sub!(/[a-zA-Z]/, '*') 1.9.3p0 :003?> end => [" \t \t *irst line ", "*econd line"] Hints: * check the difference between sub , sub! , gsub , gsub! * check character classes in regular expressions HTH, Peter *** Available for a new project *** Peter Vandenabeele http://twitter.com/peter_v http://rails.vandenabeele.com http://coderwall.com/peter_v --002354470c5c9503d304b8844e38--