Grrr, that&#x27;s not a <i>Regular</i> expression at all.  I think you&#x27;d be better off looping over the string and counting the number of ( and )s in a loop, guaranteed linear time.<p>I wish people would stop abusing regular expressions.