From: Phil Meier Date: 2007-09-25T15:55:05+09:00 Subject: Re: Extract numbers from string eggie5 schrieb: > Say I have a phone number "(555) 555-5555" and I want to extract the > numbers from it. What's the most succinct way to do this? E.g.: > > old_num = "(555) 111-5555" > new_num = "5551115555" > > old_num = "555-666-7777" > new_num = "5556667777" > Regexp and gsub is an answer. old_num = "(555) 111-5555" p old_num.gsub(/[^0-9]/, '') ==> "5551115555" old_num = "555-666-7777" p old_num.gsub(/[^0-9]/, '') ==> "5556667777" BR Phil