s = "abc 123 and 4"res = s.gsub(/\D+/, "")puts res
Standard input is empty
1234
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!