From: RichardOnRails Date: 2007-11-20T11:05:01+09:00 Subject: Re: False positives in editing data On Nov 19, 2:42 am, Harry Kakueki wrote: > > Problem solved! > > > I went through a convoluted process to determine whether any of the > > initial numbers began with a zero. I simplified it to: > > > i_thNumberHasLeadingZero = (n[i] =~ /^0+/) ? true : false > > > I apologize for raising the question. My excuse is that I was > > flailing about unable to figure out what was wrong. After I posted, > > I took a harder look and realized my big mistake: I needed to use the > > KISS method :-) > > > Best wishes, > > Richard > > If you solved your problem then you won't need this. > But, just in case you are interested in looking at it from a little > different view.... > It is not a complete solution, just an idea. > > inp = < 05Topic 5 > 1Topic 1 > 2.002.1Topic 2.2.1 > 2.1Topic 2.1 > 2.2.02Topic 2.2.2 > DATA > > err1 = inp.select{|a| a =~ /^0|\.0/} > puts "A number may not start with zero" unless err1.empty? > print err1 > puts > err2 = inp.select{|b| b =~ /^\d+\.\d+\.\d/} > puts "No more that two numbers may be prefixed" unless err2.empty? > print err2 > > Harry > > -- > A Look into Japanese Ruby List in Englishhttp://www.kakueki.com/ruby/list.html Hi Ryan, > But, just in case you are interested in looking at it from a little > different view.... > It is not a complete solution, just an idea. I AM interested, and it's a great idea. Real Ruby rather than my C- flavored Ruby :-) Just for our mutual amusement, I replaced your first criterion: err1 = inp.select{|a| a =~ /^0|\.0/} with: err1 = inp.select{|a| a =~ /^0|^\d*\.0/} to preclude false hits where the text proper might contain ".0", e.g., "7How to get 5.05% interest" Bottom line: Your code is what I really need. Thanks, again. Best wishes, Richard