> 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/ -- http://mail.python.org/mailman/listinfo/python-list