Message-ID: <A4E5A0B016B8CB41A485FC629B633CED60631C4DF8@GOLD.corp.lgc-group.com>
Date: 2014-08-15T16:36:57Z
From: S Ellison
Subject: regex pattern assistance
In-Reply-To: <1408119535.2063.16.camel@tom-laptop>
> -----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}}