How to extract a point separated number format from a string?
for example a string like this
a = 'ProductX credit 1.000'
how to to get only the 1.000 from that string?
Thank you kindly
You can use method split by space in ruby
a = 'ProductX credit 1.000'
a.split(" ").last
Result
"1.000"
Input
a='ProductX credit 1.000'
Code
p a.rpartition(/\s/).last
Output
"1.000"
.match(/\d+.\d+/)is probably the most reliable way, but it also depends on the concrete formatting of the strings and different languages may use different separators (in German it would be,instead of.)..followed by three digits? How do (much) larger or smaller numbers look like? What about negative values?