From: Alexandru Popescu Date: 2006-10-28T00:01:34+09:00 Subject: Re: a regex On 10/27/06, dblack@wobblini.net wrote: > Hi -- > > On Fri, 27 Oct 2006, Alexandru Popescu wrote: > > > On 10/27/06, Chris Gernon wrote: > >> Alexandru Popescu wrote: > >> > I have a string in the following form: 2006%2F10%2Fasdfasdf (or more > >> > generic: any_characters+%2Fany_characters+%2Frest_of_it). I am > >> > wondering if I can retrieve the groups 2006, 10, asdfasdf thru a regex > >> > >> String#split would be easier than using a regex in this case: > >> > >> irb(main):001:0> '2006%2F10%2Fasdfasdf'.split('%2F') > >> => ["2006", "10", "asdfasdf"] > >> > > > > 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. > > Regexes alone don't do anything other than specify a pattern. You > need to *use* a regular expression in some operation (like split) to > get a result. > Yes... use groupings, but what I wanted to get is not done through string.split or something, but through string =~ /pattern/ and than like in Perl whatever to have access to the groups through $1, $2, etc. ./alex -- .w( the_mindstorm )p. > > David > > -- > David A. Black | dblack@wobblini.net > Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] > DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] > [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com > [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org > >