From: Gianfranco Bozzetti Date: 2010-10-08T17:36:55+09:00 Subject: Re: regexp issue Idealone Ideally wrote: > Hi All, > I have an issue in parsing regular expression and im new to > regexp. > Varaiable = "Internation tip ($25 fee)" > 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. > > Cheers As Stefano Crocco pointed out $,(,) must be escaped. To allow any number of digits, and at least 1 use \d{1,). Moreover you must match different descriptions and check for null values. Example: var =["Internation tip1 ($9 fee)","Internation tip2 ($25 fee)", "Internation tip3 ($350 fee)","Internation tip3 ($5000 fee)", "Internation tip5"] rx =/.+(\(\$*\d{1,}\s+fee\)).*/i fmt= "%-30s %6s\n" var.each do |str| if( m=rx.match(str) ) printf fmt , str, m[1] # m[1]=first sub-expression else printf fmt, str,'Null Value' end #if end #do HTH gfb -- Posted via http://www.ruby-forum.com/.