string parsing / regexp question

Tim Chase python.list at tim.thechases.com
Wed Nov 28 12:38:12 EST 2007


> The trick is that there are extra curly braces inside the \pmatrix{ }
> strings and I don't know how to write a regexp that would count the
> number of open and close curly braces and make sure they match, so
> that it can find the correct ending curly brace.

This criterion is pretty much a deal-breaker for using regexps, 
as you can't really nest things to arbitrary depths using regexps.

You really do need a parser of sorts, and pyparsing[1] is one of 
the more popular parsers, and fairly easy to use.

-tim

[1] http://pyparsing.wikispaces.com/







More information about the Python-list mailing list