Reputation: 638
I am fetching arbitrary strings from different sources that might contain integers. Here are some examples:
"He owns 3 cars"
"John has $23 and 50 cents"
"The range is 1-12 cm"
I would like to parse them so that the output will be like:
"3"
"23-50"
"1-12"
Upvotes: 2
Views: 140
Reputation: 118299
"John has 23$ and 50 cents".scan(/\d+/).join("-") # => "23-50"
"The range is 1-12 cm".scan(/\d+/).join("-") # => "1-12"
"He owns 3 cars".scan(/\d+/).join("-") # => "3"
Upvotes: 6