From: David Rio Date: 2009-06-21T08:56:36+09:00 Subject: Re: replacing repetition of characters in string On Sat, Jun 20, 2009 at 5:44 PM, Sebastian Hungerecker wrote: > Am Sonntag 21 Juni 2009 00:05:22 schrieb David Rio: >> INPUT >> --------- >> test. AA. I greatXXrr love it. >> audi tt uu yes. >> stop here, axmmen. >> >> OUTPUT >> ------------ >> {3} test. *AA*. I great*XX**rr* love it. >> {2} audi tt uu yes. >> {1} stop here, ax*mm*en. > > I'm assuming line 2 should be  {2} audi *tt* *uu* yes Yes, that's right. I don't know why it got removed from my initial post. > DATA.each do |line| >  i = 0 >  # For each match of "any character followed by the same character" do: >  marked = line.gsub(/(.)\1/) do |match| >    i += 1 >    # return the match surrounded by asterisks from the block, which will >    # tell gsub to replace the match with that >    "*#{ match }*" >  end >  puts "{#{ i }} #{marked}" > end > __END__ > test. AA. I greatXXrr love it. > audi tt uu yes. > stop here, axmmen. > > Output: > {3} test. *AA*. I great*XX**rr* love it. > {2} audi *tt* *uu* yes. > {1} stop here, ax*mm*en. Ah.. much better. Thanks sebastian. -drd