From: Li Chen Date: 2009-01-25T23:33:05+09:00 Subject: Re: how to find the position of each match within a string David A. Black wrote: > You can examine the $~ global MatchData object, in a couple of ways: > > irb(main):003:0> "ello-hello".scan('e') do |match| > irb(main):004:1* p $~.pre_match.size > irb(main):005:1> end > 0 > 6 > => "ello-hello" > irb(main):006:0> "ello-hello".scan('e') do |match| > irb(main):007:1* p $~.offset(0)[0] > irb(main):008:1> end > 0 > 6 > => "ello-hello Hi David, Thanks. I go back and read the chapter about MatchData. And it helps me a lot. Li -- Posted via http://www.ruby-forum.com/.