user1666543
user1666543

Reputation: 685

Getting only digits out of a string

I have this string - "4,450.50 $".

I need just the numbers from this string. So in this example i would like to get the number - 4450.50 back.

How could I get it?

Upvotes: 0

Views: 86

Answers (1)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84353

str = "4,450.50 $"
Float str.scan(/[\d.]/).join
# => 4450.5

Upvotes: 2

Related Questions