JSFiddle - React, Tailwind, and code Playground

by Graham Fairweather

JavaScript

function lastIndexOfRx(string, regex) {
    var match = string.match(regex);
    
    return  match ? string.lastIndexOf(match.slice(-1)) : -1;
}

var rx = /<\/?([a-z][a-z0-9]*)\b[^>]*>?/gi;

console.log(lastIndexOfRx("", rx));
console.log(lastIndexOfRx("<i>it</i><b>bo</b>", rx));