Using Rails 5.0.1 with Ruby 2.4. How do I find the index in a string of where the nth occurrence of a regex ends? If my regex were
/\-/
and my string where
str = "a -b -c"
and I were looking for the last index of the second occurrence of my regex, I would expect the answer to be 5. I tried this
str.scan(StringHelper::MULTI_WHITE_SPACE_REGEX)[n].offset(1)
but was greeted with the error
NoMethodError: undefined method `offset' for " ":String
In the above, n is an integer that represents the nth occurrence of the regex I wish to scan for.