user1030981 user1030981 - 2 years ago 88
Ruby Question

How to get all digits from string regexp ruby

How to get all the digits from a sentence string like "Lorem 123 ipsum 456 879" => "123456879" using regexp in ruby?

Answer Source

Just replace everything else.

result = subject.gsub(/[^\d]/, '')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download