Treat well even if empty(pattern) is true.
Handle unbalanced parentheses.