From: Banzai Date: 2007-06-18T13:10:10+09:00 Subject: Re: Parsing strings On 2007-06-17 22:58:18 -0500, Dan German said: > Tim Hunter wrote: >> Dan German wrote: >>> One problem, the substring contains a ?, and is left in the resultant >>> string >>> >>> >> It would help if you'd show an actual string you have and what you'd >> like it to become. If you have two examples, even better. > > It's actually a youtube url: ex. > http://www.youtube.com/watch?v=OY8AIhbqPHo > I'm trying to remove the watch? string; the slice method works, but it > would be better if you could use something like gsub gsub(/\?.*$/,'') will delete the first question mark until the end of the string. irb(main):001:0> url = "http://www.youtube.com/watch?v=OY8AlhbqPHo"; url.gsub(/\?.*$/,'') http://www.youtube.com/watch => nil irb(main):002:0> str="a?b?c"; str.gsub(/\?.*$/,'') => "a" -- H. Asari