[Question]
  [
You are going to be given a string containing some alphabetic characters along with `[` and `]`. Your task is to split into sections that are enclosed in a "group" created by `[...]` and those that are not. e.g.
```
"absbn[mesl]meslo[eyyis]me"
->
"absbn"
"mesl"
"meslo"
"eyyis"
"me"
```
Super simple right? Well hold your horses. What happens when multiple brackets conflict? like `co[[x]t` or `m[[e]]it`? We don't have any guarantee that the brackets are matched or not nested.
The rule we are going to use is that when multiple possible groups could be made we will always choose the smallest ones. Any `[`s left without a match are just regular characters and appear in the output.
So in `co[[x]t` we could do `co` `[x` `t`, but we could also do `co[` `x` `t`. Since the group here is either `[x` or `x` we choose the smaller one and the result is `co[` `x` `t`. In the second case `me[[e]]it` there are 4 ways to make groups here, but unambiguously `me[` `e` `]it` results in the smallest group.
Your task will be to take a non-empty string of characters `a` through `z` plus two brackets of your choice (`[]`, `{}`, `()` and `<>`) and to split it as described above, providing a list of strings as output.
In cases where a group is on the boundary of the string, e.g. `aaa[b]` or `[ems]ee` you may choose to include or omit an empty string `""` on that boundary. The test cases always include them.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Answers will be scored in bytes with the goal being to minimize the size of your source code.
## Test cases
```
go[cat]me -> "go" "cat" "me"
absbn[mesl]meslo[eyyis]me -> "absbn" "mesl" "meslo" "eyyis" "me"
co[[x]t -> "co[" "x" "t"
me[[e]]t -> "me[" "e" "]t"
mon[g]]u -> "mon" "g" "]u"
msy]mesl -> "msy]mesl"
eoa[m -> "eoa[m"
a[b[ -> "a[b["
mesi]mmp[mo -> "mesi]mmp[mo"
meu[ems[mela[] -> "meu[ems[mela" "" ""
w[[[] -> "w[[" "" ""
[foo]foobar[bar] -> "" "foo" "foobar" "bar" ""
[][] -> "" "" "" "" ""
```
  
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 9 bytes
```
S`<(\w*)>
```
[Try it online!](https://tio.run/##HYxBCsJQDET3uYdQBW9QuvUAuhsDP7/EUmga6a/UXswDeLGaCpnHkBlm0rkfZbslcKob@n7izsFDdUnbNdXVfTkdm8jrJipb52hlZlOSXPII0zLwDoeua1/2pHXgzTOZAsq78REd84usrP8yqQuMBBnRKj2bPWEe/gW1EquDgGkBgni4cyjLhFA8GPwD "Retina 0.8.2 – Try It Online") Link includes test suite that switches between `[]` and `<>` and separates the output lines for each case with `-` for convenience. Explanation: Simply splits on a minimal group, capturing the contents.
The question now requires empty chunks, but the previous 10-byte version only required an extra `_` prefix to disable them:
```
_S`<(\w*)>
```
[Try it online!](https://tio.run/##HYxRCsJADET/cw@hCt6g7K8H0L8xuLsllkLTSLel9mIewIvVVMg8BuaRUaZuSNstgmMd6PvxOzsP1SVuj2usq/tyOgYX6uDO1hqaNLEKpVzyAJXS8w6DrGtX9qUx4M0TqQDCe7EBLfNMWta/TGIJSgkZbpWOVV9Q8z5DtPjXPoFpAZx4mrEnpxEe/gE "Retina 0.8.2 – Try It Online") Link includes test suite that switches between `[]` and `<>` and separates the output lines for each case with `-` for convenience. Explanation: Splits on a minimal group, capturing the contents even if it is empty, but skipping empty chunks.
[Answer]
# [R](https://www.r-project.org/), ~~68~~ ~~63~~ 62 bytes
*Edit: -1 byte thanks to pajonk*
```
function(x,`[`=gsub)"@"["",scan(t="<(\\w*)>"[" @\\1 ",x],,"")]
```
[Try it online!](https://tio.run/##fZHBjoMgEIbvfQoye9GNPex9JH2P2rRoKDERMAKpPr07uLvFA@5hRubP//06OK1uHHp/F4M16q4mG0ZXr89gOt9bU8zV4/qolQttCRe4AlSuE6bwNWDRNK/PkpPILk3zxaCab1UFUN4ykQUoi53wXEso2Qc7c0YKMCCNOqmnHCRa1xrU0g08NotyWXq3D9kcW4Ibfh8xdvP9E9xZxJn7dwzN5J6pfB7QElHyHUFCfA8VP0KsQcV5SIiNX6oiEg4Qt2yLJuRPyNqlFajf3p8pf4/YYrqyOBws6Xqu9Yja7vZM2gEUUGpHf2kQyHdckmnjPPtC3CE0HTrxaS2nasWEVAkiDbZOKh1iP63f "R – Try It Online")
Would be [55 bytes](https://tio.run/##fZJBboQwDEX3nCJKN0k1XXRbuTkJ0iigTIpE4hFONHB6atJ2YBG6sIm//vtgYFrpPg7pakeM/uonzHf6XG859mnAqGbtRkVpKiblKXdKgmrbx6s28iJF274LeZk1H6XWlSwlPUJvkwlOavEi3oxghd2scWe1qUG2oy5CcDSarSG4ZRnoGFIcJYHG38sWW3z/BPcIMJv0jOGZ3TNXqgPBAThzIFjY7sNlzhCM4I3JO4Lbk/oNyScILWXRHfkTqnaHFsLT@zPV3yN0sL@ybThZkgYTwh0CHvbctRMogwvEX2m0YA7cLvPGdfYBcEB4Ks6Gfwol25i@nLAx4jJEL5KjJHpL7qONUlfT4IZouDo7AdcezJosnVU@lN6s3w) if it wasn't for the annoying behaviour of [R](https://www.r-project.org/)'s `strsplit` function, which outputs an extra empty string if the split pattern occurs at the start of the string-to-be-split.
We first search for bracket-pairs (using `<` and `>` as brackets) that contain only letters between them, and swap these brackets for spaces. Then, we use `scan` to split the resulting string (because of the annoying `strsplit` behaviour). `Scan` has it's own problem, though, which is that it treats consecutive whitespace as a single delimiter, and so would miss any empty groups: so, we add a spurious `@` character to each group, and then remove it with `gsub` when we're done splitting.
[Answer]
# [sed](https://www.gnu.org/software/sed/), 92 21  20 bytes
```
s/<\(\w*\)>/\
\1\
/g
```
[Try it online!](https://tio.run/##LY1BCsMwDATvfklbMKH3RS/xxU7VEIiiUjUkeb3r2D5IzKwkZPzy07rlbAPCLeyPcKchuPAMbphyjsnSCmFb6GoKPs/ZCjvvvROAieZflVGBgxqLrpiItiZ21uMqrBFSKSKhzdlmEvlAtPsGFitflwhquwk0viruQA/xVqVSKX5RqofH0eGiin8 "sed – Try It Online")
Thanks to DLosc for pointing out the specs had changed, greatly simplifying my answer, and for a -3 bytes golf
-1 thanks to "emanresu A" for pointing out I could use `<>` as my bracket chars
Prints each group on its own line.
* Finds all matches of the form `[<string of chars without brackets>]`.
* Replaces them with `\n<string of chars without brackets>\n`
[Answer]
# Python3, 158 bytes:
```
import re
def f(l):
 t=''
 while l:
  if(j:=re.findall('^\[\w+\]|^\[\]',l)):yield t;yield j[0][1:-1];l=l[len(j[0]):];t=''
  else:t+=l[0];l=l[1:]
 if t:yield t
```
[Try it online!](https://tio.run/##XY5NboMwEIX3nMI77CatEnVTGXGSYSqZMBBHY4ywI0Dq3SkEVRVs5ud7T2@mm@Ldt59fXT/P1nW@j6KnpKJa1JKVTkTM0zQRw90yCV52YWv50HlPH7VtK8Ms0@8CiuFU4M86YHpmpfRkiSsRs60/4IJw1e9XzDhnYGrlipTGbMsXxIF0PC3iZfNcNSbLLRH/ouYmZ@PKyohRw1stR4VJ19s2ykamjYebiegoVeqfmjKULTgKjGvxQNNkw9F18wAjxh1zBEB4hL6FBvG5h2F6he8geQNu/wqUcLgQLDrXgfMH/gRyYfmaDeBOGgBeZP4F)
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-p`, 11 bytes
```
a^`<(\w*)>`
```
Uses `<>` for brackets. [Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgWbSSboFS7IKlpSVpuharE-MSbDRiyrU07RIgIlCJ9dFKNrmpNjapdnYlNnZw9QA)
[Verify all test cases](https://ato.pxeger.com/run?1=LY_BCoJAEIbvPsWyJw303OFn3iCQrmW4yhqC20qrmERP0kWIunTt1Jv0Nu26Hmbmm3_4Z5j7o63b147HLc8-6YpdBUsYZzHZlLBtGj77rorXb3HIEe6HVUS5V37f6MY2bBcwftQoRUdKctuIwhQnKGkacklDjmNtlmGpgQt1DpUEJC2sTzgS9TObcTY6llpAzUtRwJtMTUq1UNq3PaQy9lojQE4ZAA-otCYbhTjDhtfIzbKg9x9Mk69_)
### Explanation
Same idea as [Neil's Retina answer](https://codegolf.stackexchange.com/a/241124/16766): the smallest possible group is always one that does not include any brackets.
```
a            ; Command-line input
 ^           ; Split
  `       `  ; on this regex:
   <         ;   Opening bracket
    (   )    ;   Group the following part so it is included in the list of results:
     \w*     ;     0 or more word characters (here, letters)
         >   ;   Closing bracket
```
[Answer]
# Javascript, ~~113~~ ~~103~~ 39 bytes
```
s=>s.replace(/<(\w*)>/g,'0$10').split(0)
```
Uses `<>` as the brackets.
First time code golfing, yay! I'm pretty sure there's some regex magic which will beat this, but this was the best I could come up with.
EDIT: First version didn't properly handle strings starting or ending with groups, e.g. `<a>b<c>`
EDIT2: Shaved off 10 bytes thanks to [emanresu A](https://codegolf.stackexchange.com/users/100664/emanresu-a)
EDIT3: Figured out the regex magic
[Answer]
# [Python](https://www.python.org), 83 bytes
```
lambda s:[t for i,t in enumerate(re.split(r"\[([^][]*)\]",s))if(i&1)or t]
import re
```
[Attempt This Online!](https://ato.pxeger.com/run?1=RZDBTsMwDIbFNU8R5YCaaUPaDU3q3gFx9IJIR9pFauoqSdn6LFwmIXgneBqcNMDBru3P_u307XOc4wmH63tbHz6m2G7uvx577ZoXzcMOIm_Rc7uO3A7cDJMzXkdTeXMXxt7GyosDVPCkQK3kQYl1kNK2lb3dShqLilk3oo_cmyL9cD7Z3vDtjpEo8ppkxylWssgJvtlzIRlPCFZOj5V51f0aC5dSMT56O8SKtsi6RrkIX79vnjuEo47KmSzSoeCCcvLOCKab0AzgTOhVcghmnm34bc40d4a-fNJ47ikCRwS4qJjbKabqhSwK5gyAUYVQkubIVEI4QKfUtCBMG7qEJkJhzocsqCSCGdTgci1HdDc0sJxIQVoWrHJuBIdl31-e4ATGBXplr0EV_l-izYKdAQqiKFegRVRkjfZAtkDKRfZUoSB5tvzpHw)
This uses `re.split` which returns a list containing both the stuff between matches and those parts of matches that are in grouping parentheses.
This is then filtered to remove empty strings but only between groups; empty groups are retained.
[Answer]
# [Perl 5](https://www.perl.org/), 57 bytes
```
s/<(\w*)>/ $1 /g;s/^ (.*) $/$1/;print for split/ +/,$_,-1
```
[Try it online!](https://tio.run/##HYzBigIxEETv@Yoc5qCuGuawJ4v@ElnJSBwC6XSYjuj8/MaMh1cU1KNKWNJva@qwu74Oe3J2GK2bL@r@7O582NvBDaO7lCXmah@yWC0pVmd/3HG4HU9ja7Pg7itxMH7SKYODJtpCENY16rbcBXhTNRyAQFuRjJnoaVjXr2yCeLDxmNAtjcRcwNL7E4G1vyYPMi@gJx4i1Jn8gg79S6lRsrZTTh8 "Perl 5 – Try It Online")
[Answer]
# JavaScript, 21 bytes
```
s=>s.split(/<(\w*)>/)
```
[Try it online!](https://tio.run/##LY09c8MgDIZ3/wqfJ2gSsvdkderSoR06tr0LtsGhB8hncAO/3sVOBkmP3lcfv/JPhn42Uzx5GtSq2zW0GESYrInsDOz79sTxzFfZfjUjQS8jOtUcG9mFzoNTweKWCFTOJty9ngASxkJOASi8I3kYEZcNQ96XCiqS4LZz0ME@Hww6N4GjvVtAuVC@WAlYhBvAXkETYYlOzlBil7A4P5VtpZjVsPSKsXTMvMUkrPJjvGJ@wEt6zvzBlaaZpZp0LXnVkw9klbA0siQmObz6gVl@uNQnrC@Ht8@PdxHibPxodGaaJc75@g8)
[Answer]
# [Raku](https://raku.org/), 28 bytes
```
~«*.split(/\[<(\w*)>\]/,:v)
```
No TIO link, because the version of Raku/Perl 6 found there appears to have a regex bug. All of the test cases work fine on my local system though.
* `*.split(/.../, :v)` splits the input parameter on the given regex. The `:v` adverb causes the delimiters to be included in the returned list as well, as Match objects.
* `~«` converts everything in the split return list to strings. The nondelimiter groups are already strings, but the delimiter Match objects need to be converted.
* `\[` and `\]` match the literal square bracket delimiters.
* `<(` and `)>` cause the delimiter Match objects to only reference the enclosed text; that is, the square brackets are excluded.
* `\w*` is a sequence of letters.
All of the allowed delimiter pairs are Raku regex metacharacters, so there's no avoiding having to escape them.
]