in reply to Identifying and parsing numbers
I think the following regex should meet these conditions:
/(\-?(?:\d+(?:\.\d+)?)|(?:\.\d+))([a-z]{1,2})/g
The issue that makes this ones non-trivial is that the decimal point and digits are either a required element or an optional element depending on the presence of a whole number.
My regex should return a list containing value/unit pairs... If you want to exactly match and retreive you should use:
/^([+\-]?(?:\d+(?:\.\d+)?)|(?:\.\d+))([a-z]{1,2})$/
That is either a two-element list with the value and the unit, or an empty list.
|
|---|