From: Jeppe Jakobsen Date: 2006-02-12T10:39:59+09:00 Subject: Scanning a string for decimal numbers ------=_Part_2066_12843267.1139708384867 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Seems I accidently got my text marked as a qoute in my last mail, so I'll just send it a again: Let me see if I got it right then. I'll like to use periods only for my decimal numbers. I also need normal integers so 24. being accepted won't matter. Will this fix the problems you presented?: /[-+]?(\d+\.?\d*)(?=3D\s|$)/ I don't know if it takes care of the last problem, because I didn't understand it. 2006/2/12, Jeppe Jakobsen : > > 2006/2/12, Alexis Reigel : > > > > > > > > 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"]] > > > > > > > Some problems here: > > - signs are disregarded ("-24,4" becomes "24,4") > > - Invalid numbers are accepted: eg. "24,.4" "24,." "24." "24," > > - "." should be escaped. As you used it here, it means "any character" > > (except newline), so many invalid numbers are accepted (e.g. "24w"...) > > - If something different from whitespace follows the number, it is not > > or false accepted, e.g. "24.4." becomes "4." instead of "24.4" > > - ... > > > > > > Alexis. > > ------=_Part_2066_12843267.1139708384867--