s = 'some example 2 .png'puts s.gsub(/\s+(\.[^.]+\z)|\s/) { $1 || "_" }
Standard input is empty
some_example_2.png
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!