Thanks for the answers!! Going to go with Regexp.last_match :-)

On 11 September 2012 22:48, 7stud -- <lists / ruby-forum.com> wrote:

> 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/.
>
>