I want to take a string of characters, parse out only the numbers, and then print that string of numbers to stdout. It has to be done with one line using the ruby -e switch on the command line. It must be one line because I’m using this as part of a applescript with the do shell script command.
Here’s the code I came up with:
ruby -e '%{303-123-4567}.to_s.chars.to_a {|char| print char if char =~ /\d/}'
I realize print is being called for each digit. It’s Friday and my brain is fried. 🙂 Does anyone have any suggestions?
Thank you!
You could just use
gsub: