[
and ]
are special characters in regular expressions. They delimit a character class. If you want to match them literally, you need to escape them in the pattern like this:
RowHTML = RowHTML.replace(/\[0\]/g, '[' + (LastIndex + 1) + ']');
Or as Fabricio suggests, you only really need to escape the [
:
RowHTML = RowHTML.replace(/\[0]/g, '[' + (LastIndex + 1) + ']');