The reason is that regexes in Leex are greedy. Your regex in this case matches the longest string possible. Here’s a example using your regex and data in IEx:
iex> r = ~r/(\[[^\]]*\])+/
~r/(\[[^\]]*\])+/
iex> String.split "[Tag1 \"Value1\"] [Tag2 \"Value2\"]{comment}", r, include_captures: true
["", "[Tag1 \"Value1\"]", " ", "[Tag2 \"Value2\"]", "{comment}"]
iex> String.split "[Tag1 \"Value1\"][Tag2 \"Value2\"]{comment}", r, include_captures: true
["", "[Tag1 \"Value1\"][Tag2 \"Value2\"]", "{comment}"]
In general I find these issues become prevalent when you’re using Leex to parse instead of just tokenize. (I know this because I’ve spent hours on similar cases myself). My learning is to use Leex to tokenise and Yecc to parse.
Or look at nimble_parsec or ex_spirit


















