I need to split a string by whitespace, but not when the whitespace is found inside "()" or "[]". I found a several similar questions from here, but I couldn't find out the ideal solution.
The string I want to parse can look like this (square brackets can also be replaced with regular brackets):
(1) "Some text [more text]"
(2) "Some text[more text]"
I want them to be split up like this:
(1) ["Some", "text", "[more text]"]
(2) ["Some", "text[more text]"]
Javascript - divide by spaces unless within brackets - This question was quite similar and the answer works really well in the first (1) situation. But in the second (2) situation, it doesn't work so well. After splitting, it looks like this:
["Some", "text[more", "text]"]
Is there a simple way to achieve what I want?