MV Remove all text between two characters

Code:
CGMV_Window_EncyclopediaList.prototype.drawItem = function(index) {
    var item = this._data[index];
    var rect = this.itemRect(index);
    rect.width -= this.textPadding();
    this.changePaintOpacity(this.isEnabled(item));
    var number = CGMV.Encyclopedia.NumberEntries ? item._index + ". " : "";
    var name = item._discovered ? this.getItemName(this._symbol, item._id) : CGMV.Encyclopedia.UnknownEntry;
    
    this.drawText(number + name, rect.x+3, rect.y, rect.width, 'left');
    this.changePaintOpacity(true);
};
In this code it gives out a list of items like this :
2.png

What I want to do is delete the color code "\C[n]" from the text when it is writing it, I can delete the first 5 characters with a 'name.substring(5)' but sometimes the color code would be "\C[12]" and that substring will leave a character, what can I do to deleter everything between the '\' and the ']'? I tried replaceAll but it doesn't recognize it as a function.
You can use regular expressions for string pattern matching. There's a learning curve but they can be very useful! E.g.
  • \c[123] -> (blank):
    JavaScript:
    name = name.replace(/\\c\[\d+\]/gi, "");
  • \Abc[123] -> (blank):
    JavaScript:
    name = name.replace(/\\[A-Z]+\[\d+\]/gi, "");
g is for global ("match all" in this case); i means "case-insensitive".
Thanks a lot for the help!

Original thread: https://forums.rpgmakerweb.com/threads/remove-all-text-between-two-characters.158330/