puts [ 'ab((((cd))))ef((gh))ij(kl)mn', '((((abc));def;((ghi)))', '(((foo)) , bar)'].map {|x| x.gsub(/(\((?:\w+|\g<1>)?\))/, '')}
Standard input is empty
abefijmn ((;def;) ( , bar)
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!