http://qs1969.pair.com?node_id=345834


in reply to capturing matching parenthesis

The times I've had to cope with nested parentheses, I've used recursion -- call the recursion routine when you encounter the open paren (excellent point about the "\(" sequence, by the way), and return when you encounter the close paren (of course, there's the escape sequence there, too), resuming at the point beyond the close paren, in the original string.. I do like the idea of populating the tree structure with it, too, depending on the analysis you need to do on the whole expression. But then, I'm an old C programmer.