Removing text within parentheses (parentheses within parentheses prob)

Posted by TenJack on Stack Overflow See other posts from Stack Overflow or by TenJack
Published on 2009-12-23T02:38:32Z Indexed on 2010/05/23 16:10 UTC
Read the original article Hit count: 263

Filed under:
|
|

Hi, I am trying to remove text that is within parentheses (along with the parentheses themselves) but am having trouble with the scenario where there are parentheses within parentheses. This is the method I am using (in Ruby):

sentence.gsub(/\(.*?\)/, "")

and that works fine until I have a sentence such as:

"This is (a test (string))"

Then the above chokes. Anyone have any idea how to do this? I am completely stumped.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about regex