From: Alexandru Popescu Date: 2006-10-28T00:11:26+09:00 Subject: Re: a regex On 10/27/06, Robert Klemme wrote: > On 27.10.2006 16:39, Chris Gernon wrote: > > Alexandru Popescu wrote: > >> Thanks for all suggestions, but the requirement is to be done thru > >> regex only :-). I knew how to do it with split, but I need to do it > >> with regexps only. > > > > How about just: > > > > irb(main):001:0> match = '2006%2F10%2Fasdfasdf'.match > > /^(.*)%2F(.*)%2F(.*)$/ > > => # > > irb(main):002:0> match[1] > > => "2006" > > irb(main):003:0> match[2] > > => "10" > > irb(main):004:0> match[3] > > => "asdfasdf" > > This has a potential for disastrous backtracking with large strings. > This one is better - if you can guarantee there there is no "%" besides > the one preceding the "2F": > > => "2006%2F10%2Fasdfasdf" > >> s.match(/^([^%]*)%2F([^%]*)%2F(.*)$/).to_a > => ["2006%2F10%2Fasdfasdf", "2006", "10", "asdfasdf"] > > Or maybe even > > >> s.match(/^((?>[^%]*))%2F((?>[^%]*))%2F((?>.*))$/).to_a > => ["2006%2F10%2Fasdfasdf", "2006", "10", "asdfasdf"] > > :-) > Yep... this is the closest I got too :-). ./alex -- .w( the_mindstorm )p. > Kind regards > > robert > > >