From: Robert Klemme Date: 2010-10-08T18:07:02+09:00 Subject: Re: regexp issue On Fri, Oct 8, 2010 at 8:40 AM, Idealone Ideally wrote: > Hi All, >        I have an issue in parsing regular expression and im new to > regexp. >  Varaiable = "Internation tip ($25 fee)" First of all, "Variable" is a constant. You need to make the name start with a lowercase letter. > The $25 might vary each time, it might be $5, $ 10 so on > > I tried doing something like this which didnt work, kindly help > variable = "Internation tip (regexp:$[0-9][0-9]+ fee)" > i want the regular expression to aid both single digit or multi digit > currency. There is a simple approach and a more robust approach: irb(main):008:0> v = "Internation tip ($25 fee)" => "Internation tip ($25 fee)" irb(main):009:0> v[/\d+/].to_i => 25 irb(main):010:0> v[/\AInternation tip \(\$(\d+) fee\)\z/, 1].to_i => 25 The first regexp extracts any number, i.e. this works with differently formatted strings as long as there is at least one digit somewhere. The second one checks that your string actually follows the pattern you described. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/