If I have the string below. does someone know a regular expression to just get the "BLC.NYSE". I bought the O'Reilley book and read it when I can and I study the solutions on the list but I'm still not self sufficient with these things. Thanks. stock<-"/opt/limsrv/mark/research/equity/projects/testDL/stock_data/fhdb/US/BLC.NYSE"
Hi Mark, stock<-"/opt/limsrv/mark/research/equity/projects/testDL/stock_data/fhdb/US/BLC.NYSE"> gsub(".*/([^/]+)$", "\\1",stock)[1] "BLC.NYSE" --- On Tue, 23/9/08, markleeds at verizon.net <markleeds at verizon.net> wrote:> From: markleeds at verizon.net <markleeds at verizon.net> > Subject: [R] perl expression question > To: r-help at r-project.org > Received: Tuesday, 23 September, 2008, 10:29 AM > If I have the string below. does someone know a regular > expression to > just get the "BLC.NYSE". I bought the > O'Reilley > book and read it when I can and I study the solutions on > the list but > I'm still not self sufficient with these things. > Thanks. > > > stock<-"/opt/limsrv/mark/research/equity/projects/testDL/stock_data/fhdb/US/BLC.NYSE" > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code.
Try this:> sub(".*/", "", stock)[1] "BLC.NYSE" On Mon, Sep 22, 2008 at 8:29 PM, <markleeds at verizon.net> wrote:> If I have the string below. does someone know a regular expression to just > get the "BLC.NYSE". I bought the O'Reilley > book and read it when I can and I study the solutions on the list but I'm > still not self sufficient with these things. Thanks. > > > stock<-"/opt/limsrv/mark/research/equity/projects/testDL/stock_data/fhdb/US/BLC.NYSE" > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Hi Mark, do you mean the regex to get the portion of the address after the final slash? Something like gsub(".*/([^/]*$)", "\\1", stock, fixed=FALSE) Cheers Andrew On Mon, Sep 22, 2008 at 07:29:25PM -0500, markleeds at verizon.net wrote:> If I have the string below. does someone know a regular expression to > just get the "BLC.NYSE". I bought the O'Reilley > book and read it when I can and I study the solutions on the list but > I'm still not self sufficient with these things. Thanks. > > > stock<-"/opt/limsrv/mark/research/equity/projects/testDL/stock_data/fhdb/US/BLC.NYSE" > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/
If this is a path name, then 'basename' will work for you:> stock<-"/opt/limsrv/mark/research/equity/projects/testDL/stock_data/fhdb/US/BLC.NYSE" > basename(stock)[1] "BLC.NYSE">On Mon, Sep 22, 2008 at 8:29 PM, <markleeds at verizon.net> wrote:> If I have the string below. does someone know a regular expression to just > get the "BLC.NYSE". I bought the O'Reilley > book and read it when I can and I study the solutions on the list but I'm > still not self sufficient with these things. Thanks. > > > stock<-"/opt/limsrv/mark/research/equity/projects/testDL/stock_data/fhdb/US/BLC.NYSE" > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?