From: Jeppe Jakobsen Date: 2006-02-12T08:49:16+09:00 Subject: Scanning a string for decimal numbers ------=_Part_1666_16346009.1139701742380 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Nice, that was the thing I was looking for :) 2006/2/12, Wilson Bilkovich : > > On 2/4/06, Jeppe Jakobsen wrote: > > Hi all, how do you scan a string and avoid getting my decimal numbers > > divided into 2 numbers. > > > > Example: > > > > a =3D "24,4 + 55,2" > > a.scan! (/\d+/) > > puts a > > > > my output for a will be: > > 24 > > 4 > > 55 > > 2 > > > > But I want to keep my decimal numbers intact like this: > > 24,4 > > 55,2 > > > > > > How do I solve this problem without putting the numbers into seperate > > strings? > > > This should handle periods or commas as the separator. > > a =3D "24,4 + 55,2 + 55 - 44,0" > =3D> "24,4 + 55,2 + 55 - 44,0" > a.scan /(\d+,?.?\d*)(?=3D\s|$)/ > =3D> [["24,4"], ["55,2"], ["55"], ["44,0"]] > > ------=_Part_1666_16346009.1139701742380--