Here is my method: https://regex101.com/r/vyKG1j/1
[\s]+(?!([^[]*])|([^\(]*\)))
However, I encountered issues with encapsulated brackets like (a b (c d)) and struggled to include apostrophe search.
For example:
"a b (a (a b)) [a b c d] 'test string' (a b)"
Expected results:
["a", "b", "(a (a b))", "[a b c d]", "'test string'", "(a b)"]
It would be ideal if the solution could also handle situations like this.
For instance: "a b abcd(a b)"
Desired output:["a", "b", "abcd(a b)"]
Do you think regex is the most effective approach here?