From: Robert Dober Date: 2006-09-29T01:27:42+09:00 Subject: Re: Regular expression reformating a value ------=_Part_55871_16998319.1159460859412 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 9/28/06, Steven Ketcham wrote: > > > > I am not really sure how to do this. I have a series of number that need > parsed. Strip the zeros, if a caret > exists replace it with a slash. > > 1.) 000123^2 - should be 123/2 > 2.) 1^2 - should be 1/2 > 3.) 0001 - should be 1 > 4.) 000123 - should be 123 How about s.sub!(/^\s*0+/,"").sub(/\^/,"/") than if you need checking %r{^\s*[0-9/]+} =3D=3D=3D s which is not completely strict because of 5.) 12^34/5 Cheers Robert > I do not know how to do the condtional to exclude the slash on examples 3 > and 4. How do I prevent the addition of the slash when there is no caret > in > the number? > > > > > > reg =3D /(?:[1-9]{1}\d*)\W(?:\d*)/ > > puts reg.match("000123^2"); > > puts reg.match("123^2"); > > puts reg.match("0001"); > > puts reg.match("000123"); > > puts reg.match("123"); > > > > Thanks! > > > > > > > > > > > --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_55871_16998319.1159460859412--