It is a requirement in Regex::count_matches(). Exceptions are currently thrown if the pattern to count contains duplicate numbers and those parentheses are not balanced. That means that all expressions should have balanced parentheses even if they contain variables, even if they are contained in variables.
I don't think it's worth to go through the pain of relaxing this requirement.