import Text.Printf
where
f (ls,r:rs) ']' = (r:ls,rs)
f (ls, "") ']' = (ls, "")
f (l:ls,rs) '[' = (ls,l:rs)
f ("", rs) '[' = ("", rs)
f (ls, rs) x = (x:ls,rs)
main = forM_ ["abc[-[[/", "a[b[c]]d", "a[[[[b]]]]]]c"]
$ liftM2
(printf
"\"%s\" -> \"%s\"\n") id editor
aW1wb3J0IENvbnRyb2wuTW9uYWQKaW1wb3J0IFRleHQuUHJpbnRmCgplZGl0b3IgOjogU3RyaW5nIC0+IFN0cmluZwplZGl0b3IgPSB1bmN1cnJ5ICgoKyspIC4gcmV2ZXJzZSkgLiBmb2xkbCBmICgiIiwiIikKICAgIHdoZXJlCiAgICAgIGYgKGxzLHI6cnMpICddJyA9IChyOmxzLHJzKQogICAgICBmIChscywgICIiKSAnXScgPSAobHMsICAiIikKICAgICAgZiAobDpscyxycykgJ1snID0gKGxzLGw6cnMpCiAgICAgIGYgKCIiLCAgcnMpICdbJyA9ICgiIiwgIHJzKQogICAgICBmIChscywgIHJzKSAgeCAgPSAoeDpscyxycykKCm1haW4gOjogSU8gKCkKbWFpbiA9IGZvck1fIFsiYWJjWy1bWy8iLCAiYVtiW2NdXWQiLCAiYVtbW1tiXV1dXV1dYyJdCiAgICAgICAkIGxpZnRNMiAocHJpbnRmICJcIiVzXCIgLT4gXCIlc1wiXG4iKSBpZCBlZGl0b3IK