Re: [R] regex pattern assistance

2014-08-15 Thread arun
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 wrote: Hi, Can anyone please assist. given the string > x<-"/mnt/AO/AO Data/S01-012/120824/" I would like to extract "S01-012"

Re: [R] regex pattern assistance

2014-08-15 Thread Marc Schwartz
On Aug 15, 2014, at 11:56 AM, Tom Wright wrote: > WOW!!! > > What can I say 4 answers in less than 4 minutes. Thank you everyone. If > I can't make it work now I don't deserve to. > > btw. the strsplit approach wouldn't work for me as: > a) I wanted to play with regex and > b) the location i

Re: [R] regex pattern assistance

2014-08-15 Thread Jeff Newmiller
Must be another lucky streak. :-) --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#..

Re: [R] regex pattern assistance

2014-08-15 Thread Rui Barradas
Hello, I don't believe you need an extra package for that. Try sub("\\/mnt\\/AO\\/AO Data\\/([-[:alnum:]]*)\\/.+", "\\1", x) or, with package stringr, str_match(x,"\\/mnt\\/AO\\/AO Data\\/(.+)\\/.+") Hope this helps, Rui Barradas Em 15-08-2014 17:18, Tom Wright escreveu: Hi, Can anyone p

Re: [R] regex pattern assistance

2014-08-15 Thread Tom Wright
WOW!!! What can I say 4 answers in less than 4 minutes. Thank you everyone. If I can't make it work now I don't deserve to. btw. the strsplit approach wouldn't work for me as: a) I wanted to play with regex and b) the location isn't consistent. Nice to see email support still works, not everyt

Re: [R] regex pattern assistance

2014-08-15 Thread Marc Schwartz
On Aug 15, 2014, at 11:18 AM, Tom Wright 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

Re: [R] regex pattern assistance

2014-08-15 Thread S Ellison
> -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. >

[R] regex pattern assistance

2014-08-15 Thread Tom Wright
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 lik