From: Phrogz Date: 2006-10-28T00:30:10+09:00 Subject: Re: a regex 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. I'm unclear on what your real requirements are, but here are some possible alternatives: s = "2006%2F10%2Fasdfasdf" p s.scan( /.+?(?=%2F|$)/ ).map{ |v| v.gsub( '%2F', '' ) } #=> ["2006", "10", "asdfasdf"] p s.gsub( '%2F', "\n" ).scan( /[^\n]+/ ) #=> ["2006", "10", "asdfasdf"] p s.match( /^(.+?)%2F(.+?)%2F(.+?)$/ ).to_a #=> ["2006%2F10%2Fasdfasdf", "2006", "10", "asdfasdf"]