String.lastIndexOf
lastIndexOf($substring, $options={}) -> number
Description
Find the position of $matchString., starting at the end of the string.
If the substring does not exist, it will return 0.
'one fish two fish'.lastIndexOf('one')
//= 1
'one fish two fish'.lastIndexOf('fish')
//= 14        ^
'one fish two fish'.lastIndexOf('bird')
//= 0
Options
| Option | Value | Description | 
|---|---|---|
| ignoreCase | true/false | Match upper and lowercase versions of each character. | 
| startIndex | number | Start at index position (default: 1) | 
'one fish two fish'.lastIndexOf('Two Fish', -ignoreCase)
//= 10    ^
'one fish two fish'.lastIndexOf('Fish', { ignoreCase, startIndex: 10 })
//= 14        ^
Regex Patterns
The $matchString argument can also be a Regex.
// \d+ = one or more consecutive digits 'ABC 123 789'.lastIndexOf(rx'\d+') //= 9 // i = ignore case 'abc XYZ def XYZ'.lastIndexOf(rx'xyz'i) //= 13