From: Srijayanth Sridhar Date: 2009-05-06T20:06:36+09:00 Subject: Re: Ruby Regex --001e680f102035c1a104693c63d5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit He only wanted the first occurrence of zip I think. Jayanth On Wed, May 6, 2009 at 4:33 PM, Robert Klemme wrote: > 2009/5/6 Robert Dober : > > On Wed, May 6, 2009 at 9:18 AM, Sriram Varahan > wrote: > >> Hello, > >> > >> > >> I have this string: > >> > >> "d:\\home\\abc2.zip\\abc.zip\\abc.com" > >> > >> I need to extract the contents up to the first occurrence of zip which > >> would be: > >> > >> "d:\\home\\abc2.zip" > >> > >> When i use a regex like: \(.+).zip\ it gives me the entire contents upto > >> the second zip. > > Why are you so greedy Sriram ;)? Well it is not you it is the "+" > > which is greedy, try the non greedy version "+?" it might just give > > you a nice surprise. > > Why not use File.dirname? > > irb(main):003:0> File.dirname "d:\\home\\abc2.zip\\abc.zip\\abc.com" > => "d:\\home\\abc2.zip\\abc.zip" > > Cheers > > robert > > > -- > remember.guy do |as, often| as.you_can - without end > http://blog.rubybestpractices.com/ > > --001e680f102035c1a104693c63d5--