I want to remove "un-partnered" parentheses from a string.
I.e., all (
's should be removed unless they're followed by a )
somewhere in the string. Likewise, all )
's not preceded by a (
somewhere in the string should be removed.
Ideally the algorithm would take into account nesting as well.
E.g.:
"(a)".remove_unmatched_parents # => "(a)"
"a(".remove_unmatched_parents # => "a"
")a(".remove_unmatched_parents # => "a"