I would like to split the lines as follows:
x <- "abc-1230-xyz-[def-ghu-jkl---]-[adsasa7asda12]-s-[klas-bst-asdas foo]"
by a dash ( -) provided that these strokes should not be contained within the pair []. Expected Result:
c("abc", "1230", "xyz", "[def-ghu-jkl---]", "[adsasa7asda12]", "s",
"[klas-bst-asdas foo]")
Notes:
- No nesting square brackets inside each other.
- Square brackets can contain any characters / numbers / characters except square brackets.
- The rest of the string is also variable, so we can only assume that we break up
-when it's not inside [].
There is a similar question for python ( How to break a string with commas located outside the brackets? ), But I have not yet been able to fine tune this to my script.