Code 1 s=".sdrawkcab si gnirts sihT" 2 puts s.reverse #This string is backwards. 3 puts s #.sdrawkcab si gnirts sihT 4 s.reverse! 5 puts s #This string is backwards. 6 7 puts "Three little words".split(/\s+/) 8 #Three 9 #little10 #words11 12 puts "Three little words".split(/(\s+)/)13 #Three14 #15 #little16 #17 #words
Because the regular expression /(\s+)/ includes a set of parentheses, the separator strings themselves are included in the returned list.