s = 'some example 2 .png'puts s.gsub(/\s+(\.[^.]+\z)|\s/) { Regexp.last_match(1) ? Regexp.last_match(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!