How do I split a string by whitespaces if it is not surrounded with this kind of bracket [ ]
So the string " book [new interesting book] buy it " should be split in
book
new interesting book
buy
it
or
book
[new interesting book]
buy
it
Thank you!
Does it have to be regex? You can do it in one iteration just by counting how many brackets ware before space to determine if that space should be replaced by new line mark or not.
Out: