parseFieldaccepts a string, splits it into a list of all substrings between left or right square brackets ( [or ]), and then returns all elements from this list that have at least one character (basically excluding an empty string, "").
- Regexp is
/\[|\]/similar to saying "division by [and ]" array.filter(s => s) - , false. , JavaScript, , , ("").
:
function parseField (field) {
return field
.split(/\[|\]/)
.filter(function(s){ return s })
}
console.log(parseField('[stuff][thing]'))
console.log(parseField('[]'))