I have a string and need to split it by whitespace but if there would be some words inside brackets I need to skip it.
For example,
input: 'tree car[tesla BMW] cat color[yellow blue] dog'
output: ['tree', 'car[tesla BMW]', 'cat', 'color[yellow blue]', 'dog']
if I use simple .split(' ') it would go inside brackets and return an incorrect result.
Also, I've tried to write a regex, but unsuccessfully :(
My last regex looks like this .split(/(?:(?<=\[).+?(?=\])| )+/) and return ["tree", "car[", "]", "cat", "color[", "]", "dog"]
Would be really grateful for any help