Leex regex’s are greedy - they will return the longest match. Which is why you are getting {code,50,"[code]\nzz\nzzz\n[/code]\n\ntest\n\n[code]\nzz\nyyy\n[/code]"}
In part this is because you are trying to both tokenise and parse at the same time with a tool that is designed for tokenising. Probably better to use @OvermindDL1’s ex_spirit
he described above.
If you choose to continue with Leex, then simplify your tokenising and use Yecc for parsing - it will save you a lot of grief over trying to coerce Leex into something its not designed for.
I think your basic tokens are [
, ]
, \\
, :
, [a-zA-Z]+
and \n
from which you can then parse the format you’re using with a simple parser in Yecc.