From: Clement Ow Date: 2008-06-25T11:05:11+09:00 Subject: Re: Regex extracting certain characters Pe単a, Botp wrote: > From: clement.ow@asia.bnpparibas.com > # C:/Ruby/20080205/2008 > # C:/Ruby/2008 > # I need a regular expression which can select just 2008 and utilise the > # string that contains just 2008 instead of 20080205. > > pardon if i'm mistaken, but maybe you may want to get the "ending" part > of that pathname w/o using regex, > > eg, > > s > #=> "C:/Ruby/20080205/2008" > > year=s.split("/").last > #=> "2008" > > year == "2009" > #=> false > > year == "2008" > #=> true > > kind regards -botp Thank you for all your prompt replies =) I think I did not explain myself clearer.. What I want to test for is actually just solely '/2008' which can be anywhere in the path name, maybe citing some examples would be clearer. These are the kind of strings i want to test for: C:/2008/ruby or C:/ruby/test/2008 or C:/ruby/test/2008/testing These are the kind of strings that I want to eliminate: C:/20080229/ruby or C:/ruby/test/20080502 or C:/ruby/test/20080405/testing or C:/29022008/ruby In other words, I want to just test for "/" followed by "2008" in a given string. Thanks. -- Posted via http://www.ruby-forum.com/.