From: 7stud -- Date: 2012-09-12T05:48:10+09:00 Subject: Re: String iterate through regex matches with possition Vicente Bosch wrote in post #1075485: > > Is there any way to scan the string for matches where I get the index > possition ? > str = 'BS HD SP SP EP SP NL EP EP FT BS' str.scan(/ SP \s* (?:NL)* \s* EP /xms) do |match| md = Regexp.last_match puts "#{match.inspect} => #{md.offset(0)}" end --output:-- "SP EP" => [9, 14] "SP NL EP" => [15, 23] -- Posted via http://www.ruby-forum.com/.