>'abcdefabc' =~ 'abc' returns 0
>
>How do I get it to return 6? ... finding the second abc?
>
>Or return 9 in this case:
>
>'abcdefabcabc' =~ 'abc'
>
>Chris Morris
>chris.morris / snelling.com

A cluge, but:

a = 'abcdefabc'

p = 'abc'

i = (a.reverse =~ p.reverse) + a.length - p.length

irb(main):014:0> a = 'abcdefabc'
"abcdefabc"
irb(main):015:0>
irb(main):016:0* p = 'abc'
"abc"
irb(main):017:0>
irb(main):018:0* i = (a.reverse =~ p.reverse) + a.length - p.length
6
irb(main):019:0>