From: Ammar Ali Date: 2010-11-04T01:56:07+09:00 Subject: Re: UTF-8 aware chop for 1.8? On Wed, Nov 3, 2010 at 6:38 PM, James Edward Gray II wrote: > On Nov 3, 2010, at 11:33 AM, Ammar Ali wrote: >> By the way, the m options seems superfluous in James' version. I get >> the same results without it. > > It's not: > >>> "\n".sub(/.\z/u, "") > => "\n" >>> "\n".sub(/.\z/mu, "") > => "" > > Using gsub() over sub() was a dumb mistake on my part though.  sub() is all you need, since it can only match once. Thanks for the clarification. My method now looks like: def chop_utf8(s) return unless s lead = s.sub(/.\z/mu, "") last = s.scan(/.\z/mu).first last = '' unless last [lead, last] end Short and sweet. Cheers, Ammar