str = "a * ((b-c)/(d-e) - f) * g"
reg = /(?                  # begin named expression
          \(               # match open paren
          (?:              # non-capturing group
             (?>           # possessive subexpr to match:
                 \\[()]    #  either an escaped paren
               |           # OR
                 [^()]     #  a non-paren character
             )             # end possessive
             |             # OR
             \g            # a nested parens group (recursive call)
           )*              # repeat non-captured group zero or more
           \)              # match closing paren
        )                  # end named expression
      /x
m = reg.match(str).to_a    # ["((b-c)/(d-e) - f)", "((b-c)/(d-e) - f)"]

