From: "David A. Black" Date: 2009-06-21T20:50:00+09:00 Subject: Re: replacing repetition of characters in string --1926193751-220452576-1245584987=:7085 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-220452576-1245584987=:7085" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-220452576-1245584987=:7085 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Sun, 21 Jun 2009, David Rio wrote: > On Sat, Jun 20, 2009 at 10:18 PM, Morris Keesan wrote: >> This problem is a little under-specified, > > Yes, my bad. > >> and it would be worth asking >> exactly what your friend is trying to accomplish. >> As a quick question, what should happen if the input contains THREE of the >> same character? �Should "aaa" become >> aaa >> *aa*a >> *aaa* >> *a*a*a* >> or something else? > > *aa*a, which is what Sebastian's code does. Mine does too (I lucked out :-) str = "Helllo" str.gsub(/((\w)\2)/,'*\1*') # "He*ll*lo" David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) "Ruby 1.9: What You Need To Know" Envycasts with David A. Black http://www.envycasts.com --1926193751-220452576-1245584987=:7085-- --1926193751-220452576-1245584987=:7085--