Well understandably the paranethesis matching of this is
extremely difficult. It's my intuition that regex isn't
the right solution-- reformulating the problem is. :) At
the very least, you could just rip out all s
and get back to single character pairing with nesting. What
strikes me as odd is why the data would even be in that
format to begin with... Surely you could come up with a
more meaningful output format...
(tedv)Re2: Template system and substitution
Download Code Replies are listed 'Best First'.
Well if you code up an alternate way to parse this, then I'd be interested in seeing a benchmark comparison. I think my solution was pretty simple, efficient, and correct.
My suggestion would be to use a templating module (probably Template Toolkit based on what others say about these things). But if that isn't acceptable for whatever reasons, I still stand by my suggestion as quite reasonable.
I don't see how riping out brackets would help much since there will probably be plenty of brackets that aren't delimiters both inside and outside of the delimited blocks.
Thinking of how I'd catch all unmatched delimiters, I'd probably do this:
...and I just realized one minor way in which this is
inferior to my original solution.
This solution always interprets [|] as a
starting delimiter, never as an ending delimiter. But
given the unlikelyhood of needing to embed code that ends
in [ and the (moderate) difficulty in "fixing"
this solution in this respect, I'd just document this as a