# Remove all parentheses and the text inside them.
#
# @param text [String] The input string
# @return [String] The cleaned string
def remove_parentheses_with_content(text)
# Remove parentheses and everything inside them
cleaned = text.gsub(/\([^)]*\)/, " ")
# Collapse multiple spaces into one
cleaned = cleaned.split.join(" ")
# Final trim of leading/trailing spaces
cleaned.strip
end
str = "(An) API (API) (is a) (connection) connects (between) computer programs"
output = remove_parentheses_with_content(str)
puts output
=begin
run:
API connects computer programs
=end