Am Sonntag 21 Juni 2009 00:05:22 schrieb David Rio:
{1} stop here, axmmen.
I’m assuming line 2 should be {2} audi ttuu yes
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 greatXX**rr love it.
{2} audi ttuu yes.
{1} stop here, axmmen.
This problem is a little under-specified, 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 aaa aaa aaa
or something else?
On Sat, Jun 20, 2009 at 10:18 PM, Morris Keesan[email protected]
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 aaa aaa aaa
or something else?