From: Sam Duncan Date: 2012-12-05T03:41:59+09:00 Subject: Re: Extract number (float) from string On 12/05/2012 07:31 AM, Alexander G. wrote: > Hi Please advice how to extract exact number from string: > > $5.99 /LB > > I need to get 5.99 as float number > > Thank you in advance > How about; > irb 1.9.3p125 :001 > s = '$5.99 /LB' => "$5.99 /LB" 1.9.3p125 :002 > s.match(/^\$(\d+\.\d+).*$/)[1].to_f => 5.99 You may want to split it into steps and do some error checking, or just wrap it in a rescue, depending on where your input comes from and where your output is going. Sam