string replace

string replace

Please help me on this string replace, from "element[-1].unit" to "element[0].unit", I have tried this

str = str.replace("element\\[-1\\]/gi", "element[0]");

All doesn't work.

Thanks.