Message-ID: <1408127843.57071.YahooMailNeo@web142601.mail.bf1.yahoo.com>
Date: 2014-08-15T18:37:23Z
From: arun
Subject: regex pattern assistance
In-Reply-To: <1408119535.2063.16.camel@tom-laptop>
Hi Tom,
You could try:
library(stringr)
str_extract(x, perl("(?<=[A-Za-z]{4}/).*(?=/[0-9])"))
#[1] "S01-012"
A.K.
On Friday, August 15, 2014 12:20 PM, Tom Wright <tom at maladmin.com> wrote:
Hi,
Can anyone please assist.
given the string
> x<-"/mnt/AO/AO Data/S01-012/120824/"
I would like to extract "S01-012"
require(stringr)
> str_match(x,"\\/mnt\\/AO\\/AO Data\\/(.+)\\/+")
> str_match(x,"\\/mnt\\/AO\\/AO Data\\/(\\w+)\\/+")
both nearly work. I expected I would use something like:
> str_match(x,"\\/mnt\\/AO\\/AO Data\\/([\\w -]+)\\/+")
but I don't seem able to get the square bracket grouping to work
correctly. Can someone please show me where I am going wrong?
Thanks,
Tom
______________________________________________
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.