I want to get the index of the last occurrence of a character in a string which is part of a match string. What's the most efficient way to do this?
Something like match(/[\.,;]/g) but I want the index in the original string of the last element of the returned array, the way that match(/[\.,;]/) gives the index of the first match.
E.g., if string is Hello, this is a test. foo I want the index of the last period/comma/semicolon.
The best solution I've come up with is reversing the string and finding first match:
text.length - text.split('').reverse().join('').match(/[\.,;]/).index - 1