Alexis Reigel
2/12/2006 12:41:00 AM
>
> This should handle periods or commas as the separator.
>
> a = "24,4 + 55,2 + 55 - 44,0"
> => "24,4 + 55,2 + 55 - 44,0"
> a.scan /(\d+,?.?\d*)(?=\s|$)/
> => [["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.