From: w_a_x_man Date: 2010-10-02T22:55:15+09:00 Subject: Re: Ruby String: How do I strip anything between two parenthesis On Oct 1, 9:20 pm, Frank Guerino wrote: > Hi, > > Given a string that contains one or more substrings within parenthesis, > such as: > > myString = 'This is (variable length substring #1) (variable length > substring #2) string' > > How would I effectively strip out anything between any two parenthesis > and replace it with a blank (eliminating such substrings) such that it > would look like: > > myString = 'This is a string' > > I'm assuming the answer would be a combination of the string "remove" > command and the use of regular expressions but can't seem to get it to > work. > > Thanks for any help you can offer. > > My Best, > > Frank > -- > Posted viahttp://www.ruby-forum.com/. my_string = "This is (variable length substring #1) " + "(variable length substring #2) string" my_string.gsub( /\(.*?\)/, " " ).squeeze(" ") ==>"This is string"