> -----Original Message-----
> > x<-"/mnt/AO/AO Data/S01-012/120824/"
> 
> I would like to extract "S01-012"


> gsub("/mnt/AO/AO Data/(.+)/.+", "\\1", x)

#does it, as does
> gsub("/mnt/AO/AO Data/([\\w-]+)/.+", "\\1", x, perl=TRUE)    # \w is perl RE; 
> the default is POSIX, which would be. 
> gsub("/mnt/AO/AO Data/([[:alnum:]-]+)/.+", "\\1", x)  

#and
> str_match(x,"/mnt/AO/AO Data/(.+)/.+")
> str_match(x,"/mnt/AO/AO Data/([[:alnum:]-]+)/.+")   #again, needs POSIX, not 
> perl RE

You had also, btw, missed the '.' in the closing '.+', meaning that your regex 
was looking for '/+', that is, multiple instances of '/'

Steve E



*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
R-help@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.

Reply via email to