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(.*)$/ > => #<MatchData:0x1cf404> > 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"] :-) Kind regards robert