longest common valid Parenthess + regular expression matchng