Answer the question
In order to leave comments, you need to log in
How should the pattern for the string "[a][1][b][2]" look like?
There is a need to write a regular expression to extract data from brackets, 4 brackets in a row. This form does not work:
(/\[([^\]]+)\]{4,4}$/g).exec("[1][2][3][4]")
Answer the question
In order to leave comments, you need to log in
const str = "[a][1][b][2]";
console.log(str.substr(1, str.length - 2).split('][')); // ['a', '1', 'b', '2']
const str = " [a] [1] [b] [2] ".trim();
console.log(str.substr(1, str.length - 2).split(/\]\s*\[/)); // ['a', '1', 'b', '2']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question