Remove comma out of brackets - Regex

3

I'm trying to remove the comma that is located outside the brackets of the following excerpt:

2||Azul||Cor||["#1983ff", "#1983ff"],3||Amarelo||Cor||["#fff73d"]

I need the return, this way:

2||Azul||Cor||["#1983ff", "#1983ff"]3||Amarelo||Cor||["#fff73d"]

Can some ninja in regex give me a hand in this? (The above excerpt has no variation, it always turns out that way.) Thank you.

    
asked by anonymous 31.10.2016 / 20:10

2 answers

6

Assuming the principle that your return will have this format, you can simply:

var retorno =  string.replace("],","]");
    
31.10.2016 / 20:13
2

A simpler way to remove the comma, ignoring the rule of brackets in the sentence, using regular expression, as below, it replaces: (comma + number) / first house, hair (number) / second house:

var string = '2||Azul||Cor||["#1983ff", "#1983ff"],3||Amarelo||Cor||["#fff73d"]';

var rtn = string.replace(/(,)([0-9]+)/gi,'$2');

console.log(rtn);
    
31.10.2016 / 22:00