Javascript String lastIndexOf(re, ndx)
String.prototype.lastIndexOf = function(re, ndx){ let s = re.toString().replace(/\//g, ''); if (ndx === undefined) ndx = this.length - 1; if (s[0] !== '^') s = '^' + s; else ndx = 0;//from ww w . j a v a 2s . co m re = new RegExp(s, 'g'); for (let i = ndx; i >= 0; i--) { const str = this.slice(i); if (re.test(str)) return i; } return -1; };