I would use:
number = str[ /\d*(?:\.\d+)?/ ]
Or, if values ββless than 1.0 require a start of 0,
number = str[ /\d+(?:\.\d+)?/ ]
If you can have other numbers on the line and just want (the first) that has a dollar sign in front of it:
number = str[ /\$\s*(\d+(?:\.\d+)?)/, 1 ]
If this guarantees that after this there will be (should) be a decimal place and digits (digits):
number = str[ /\$\s*(\d+\.\d+)/, 1 ]
We hope you can mix and match some of these solutions to get what you need.
source share