Begin forwarded message: > From: "Lee Butterman" <leebutterman / gmail.com> > Date: April 22, 2006 10:25:22 PM CDT > To: submission / rubyquiz.com > Subject: Please forward: Ruby Quiz Submission / Text Munging > > class String > def shuffle() split('').sort_by {rand}.join end > end > > def munge s > eac_wor_ = /[a-z]+(?=[a-z])/i > s.gsub(eac_wor_) {|s| s[0..0]+s[1..-1].shuffle} > end > > while gets > print munge($_) > end > > __END__ > the only bit of magic is the regexp; > it relies on the left-to-right matching > to match the first character of a word greedily > up to the next-to-last (hence, eac_wor_). > > this was great fun! regular expressions are always a hoot and a half > > lee