From: Josh Cheek Date: 2010-10-02T13:53:18+09:00 Subject: Re: Ruby String: How do I strip anything between two parenthesis --00163649a1f5de4e6804919b1525 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Oct 1, 2010 at 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 via http://www.ruby-forum.com/. > > What if your substrings have parentheses in them? How do you know, when you come to a parenthesis, whether it terminates your substring, or is a character within your substring? Example: myString = '1(a)2(b)3' That could be either "1(substring)3" where substring is "a)2(b" Or it could be "123" with two substrings of "a" and "b" How do you know which it supposed to be? --00163649a1f5de4e6804919b1525--