Re: [R] Regular expression help

2017-10-10 Thread David Winsemius
> On Oct 9, 2017, at 6:08 PM, Georges Monette wrote: > > How about this (I'm showing it as a pipe because it's easier to read that > way): > > library(magrittr) > "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587" %>% > strsplit(' ') %>% > unlist %>% > sub('^[^/]*/*','',.) %>% >

Re: [R] Regular expression help

2017-10-09 Thread Georges Monette
How about this (I'm showing it as a pipe because it's easier to read that way): library(magrittr) "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587" %>%   strsplit(' ') %>%   unlist %>%   sub('^[^/]*/*','',.) %>%   sub('^[^/]*/*','',.) %>%   paste(collapse = ' ') Georges Monette -- Geo

Re: [R] Regular expression help

2017-10-09 Thread Duncan Murdoch
On 09/10/2017 12:06 PM, William Dunlap wrote: "(^| +)([^/ ]*/?){0,2}", with the first "*" replaced by "+" would be a bit better. Thanks! I think I actually need the *, because theoretically the b part of the word could be empty, i.e. "a//c" would be legal and should become "c". Duncan Murd

Re: [R] Regular expression help

2017-10-09 Thread Duncan Murdoch
On 09/10/2017 11:23 AM, Ulrik Stervbo wrote: Hi Duncan, why not split on / and take the correct elements? It is not as elegant as regex but could do the trick. Thanks for the suggestion. There are likely many thousands of lines of data like the two real examples (which had about 5000 and 60

Re: [R] Regular expression help

2017-10-09 Thread William Dunlap via R-help
"(^| +)([^/ ]*/?){0,2}", with the first "*" replaced by "+" would be a bit better. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Oct 9, 2017 at 8:50 AM, William Dunlap wrote: > > x <- "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587" > > gsub("(^| *)([^/ ]*/?){0,2}", "\\1", x) >

Re: [R] Regular expression help

2017-10-09 Thread William Dunlap via R-help
> x <- "f 147/1315/587 2820/1320/587 3624/1321/587 1852/1322/587" > gsub("(^| *)([^/ ]*/?){0,2}", "\\1", x) [1] " 587 587 587 587" > y <- "aa aa/ aa/bb aa/bb/ aa/bb/cc aa/bb/cc/ aa/bb/cc/dd aa/bb/cc/dd/" > gsub("(^| *)([^/ ]*/?){0,2}", "\\1", y) [1] "cc cc/ cc/dd cc/dd/" Bill Dunlap TIBCO Sof

Re: [R] Regular expression help

2017-10-09 Thread peter dalgaard
> On 9 Oct 2017, at 17:02 , Duncan Murdoch wrote: > > I have a file containing "words" like > > > a > > a/b > > a/b/c > > where there may be multiple words on a line (separated by spaces). The a, b, > and c strings can contain non-space, non-slash characters. I'd like to use > gsub() to

Re: [R] Regular expression help

2017-10-09 Thread Eric Berger
Hi Duncan, You can try this: library(readr) f <- function(s) { t <- unlist(readr::tokenize(paste0(gsub(" ",",",s),"\n",collapse=""))) i <- grep("[a-zA-Z0-9]*/[a-zA-Z0-9]*/",t) u <- sub("[a-zA-Z0-9]*/[a-zA-Z0-9]*/","",t[i]) paste0(u,collapse=" ") } f("f 147/1315/587 2820/1320/587 3624/1321

Re: [R] Regular expression help

2017-10-09 Thread Ulrik Stervbo
Hi Duncan, why not split on / and take the correct elements? It is not as elegant as regex but could do the trick. Best, Ulrik On Mon, 9 Oct 2017 at 17:03 Duncan Murdoch wrote: > I have a file containing "words" like > > > a > > a/b > > a/b/c > > where there may be multiple words on a line (se

[R] Regular expression help

2017-10-09 Thread Duncan Murdoch
I have a file containing "words" like a a/b a/b/c where there may be multiple words on a line (separated by spaces).  The a, b, and c strings can contain non-space, non-slash characters. I'd like to use gsub() to extract the c strings (which should be empty if there are none). A real exa

Re: [R] regular expression help

2017-06-08 Thread Ashim Kapoor
Dear Enrico, Many thanks and Best Regards, Ashim. On Thu, Jun 8, 2017 at 5:11 PM, Enrico Schumann wrote: > > Zitat von Ashim Kapoor : > > > Dear All, >> >> My query is: >> >> Do we always need to use perl = TRUE option when doing ignore.case=TRUE? >> >> A small example : >> >> my_text = >> "RE

Re: [R] regular expression help

2017-06-08 Thread Enrico Schumann
Zitat von Ashim Kapoor : Dear All, My query is: Do we always need to use perl = TRUE option when doing ignore.case=TRUE? A small example : my_text = "RECOVERY OFFICER-II\nDEBTS RECOVERY TRIBUNAL-III\n RC No. 162/2015\nSBI VS RAMESH GUPTA.\nDated: 01.03.2016 Item no.01

[R] regular expression help

2017-06-08 Thread Ashim Kapoor
Dear All, My query is: Do we always need to use perl = TRUE option when doing ignore.case=TRUE? A small example : my_text = "RECOVERY OFFICER-II\nDEBTS RECOVERY TRIBUNAL-III\n RC No. 162/2015\nSBI VS RAMESH GUPTA.\nDated: 01.03.2016 Item no.01\n Present: Ms. Sonakshi, t

Re: [R] regular expression help

2014-06-30 Thread C Lin
, 29 Jun 2014 13:16:26 -0700 > Subject: Re: [R] regular expression help > To: bac...@hotmail.com > CC: dwinsem...@comcast.net; r-help@r-project.org > >> what's the difference between [:space:]+ and[[:space:]]+ ? > > The pattern '[:space:]' matches any of

Re: [R] regular expression help

2014-06-29 Thread William Dunlap
ace:]+ instead > of [[:space:]]+ > what's the difference between [:space:]+ and[[:space:]]+ ? > > Thanks so much! > Lin > > >> From: wdun...@tibco.com >> Date: Fri, 27 Jun 2014 02:35:54 -0700 >> Subje

Re: [R] regular expression help

2014-06-27 Thread arun
ring you > are testing > so try this > > grep('[/]*\\[/]*',test) > > Duncan > > Duncan Mackay > Department of Agronomy and Soil Science > University of New England > Armidale NSW 2351 > Email: home: mac...@northnet.com.au > > -Original Message

Re: [R] regular expression help

2014-06-27 Thread C Lin
! Lin > From: wdun...@tibco.com > Date: Fri, 27 Jun 2014 02:35:54 -0700 > Subject: Re: [R] regular expression help > To: dwinsem...@comcast.net > CC: bac...@hotmail.com; r-help@r-project.org > > You can use parentheses to factor out the common string in David's >

Re: [R] regular expression help

2014-06-27 Thread William Dunlap
ry this >>> >>> grep('[/]*\\[/]*',test) >>> >>> Duncan >>> >>> Duncan Mackay >>> Department of Agronomy and Soil Science >>> University of New England >>> Armidale NSW 2351 >>> Email: home: mac...@northnet.com.a

Re: [R] regular expression help

2014-06-26 Thread David Winsemius
D1$|^AARSD1', test) > grepl('^AARSD1//$|^AARSD1 //$|^//AARSD1$|^AARSD1$', test) [1] FALSE FALSE TRUE TRUE TRUE TRUE -- David. > > Thanks, > Lin > > >> From: dulca...@bigpond.com >> To: bac...@hotmail.co

Re: [R] regular expression help

2014-06-26 Thread C Lin
7;//AARSD1','AARSD1'); I want to match only 'AARSD1//','AARSD1 //','//AARSD1','AARSD1' Thanks, Lin   ---------------- > From: dulca...@bigpond.com > To: bac...@hotmail.com; r-help@r-project.org > Subject: RE: [R] r

Re: [R] regular expression help

2014-06-26 Thread Duncan Mackay
al Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of C Lin Sent: Friday, 27 June 2014 10:05 To: r-help@r-project.org Subject: [R] regular expression help Dear R users, I need to match a string. It can be followed or preceded by whitespace or // or no

[R] regular expression help

2014-06-26 Thread C Lin
Dear R users, I need to match a string. It can be followed or preceded by whitespace or // or nothing. How do I code it in R? For example: test <- c('AARSD11','AARSD1-','AARSD1//','AARSD1 //','//AARSD1'); grep('AARSD1(\\s*//*)',test); should return 3,4,5 and 6. Thanks in advance for your help.

Re: [R] regular expression help to extract specific strings from text

2010-04-01 Thread Tony B
Thank you guys, both solutions work great! Seems I have two new packages to investigate :) Regards, Tony Breyal On 31 Mar, 14:20, Tony B wrote: > Dear all, > > Lets say I have the following: > > > x <- c("Eve: Going to try something new today...", "Adam: Hey @Eve, how are > > you finding R? #rs

Re: [R] regular expression help to extract specific strings from text

2010-03-31 Thread hadley wickham
On Wed, Mar 31, 2010 at 8:20 AM, Tony B wrote: > Dear all, > > Lets say I have the following: > >> x <- c("Eve: Going to try something new today...", "Adam: Hey @Eve, how are >> you finding R? #rstats", "Eve: @Adam, It's awesome, so much better at >> statistics that #Excel ever was! @Cain & @Abl

Re: [R] regular expression help to extract specific strings from text

2010-03-31 Thread Gabor Grothendieck
strapply in gsubfn can extract matches based on content which seems to be what you want: library(gsubfn) f <- function(...) sapply(list(...), paste, collapse = ", ") DF <- data.frame(x, Source = strapply(x, "^(\\w+):", c, simplify = f), Mentions = strapply(x, "@(\\w+)", c, simpli

[R] regular expression help to extract specific strings from text

2010-03-31 Thread Tony B
Dear all, Lets say I have the following: > x <- c("Eve: Going to try something new today...", "Adam: Hey @Eve, how are > you finding R? #rstats", "Eve: @Adam, It's awesome, so much better at > statistics that #Excel ever was! @Cain & @Able disagree though :(", "Adam: > @Eve I'm sure they'll so

Re: [R] Regular expression help

2009-12-07 Thread Gabor Grothendieck
If I understand correctly you wish to extract strings of digits more than 5 characters long: s <- c("UV7C11-F9-E1 MCS#9831019", "MCS Lot #9512516") library(gsubfn) strapply(s, "\\d{6,}", c) Depending on what you want to get back you might wish to add the simplify=TRUE argument to strapply, as wel

Re: [R] Regular expression help

2009-12-07 Thread Phil Spector
Ramya - Try strings = c('UV7C11-F9-E1 MCS#9831019','MCS Lot #9512516') sub('^.*?(\\d{5,}).*?$','\\1',strings,perl=TRUE) [1] "9831019" "9512516" The regular expression finds the first string of five or more numbers in the strings. Since you said the numbers could occur anywhere in the stri

Re: [R] Regular expression help

2009-12-07 Thread Marc Schwartz
On Dec 7, 2009, at 5:04 PM, Ramya wrote: Hi there I have a string like this i want to extract 9831019 from this string i used a regular expresion \d+ by which i can only make it to see 7 and returns. This type of number(9831019) appears in any part of the string and is definitely more t

[R] Regular expression help

2009-12-07 Thread Ramya
Hi there I have a string like this i want to extract 9831019 from this string i used a regular expresion \d+ by which i can only make it to see 7 and returns. This type of number(9831019) appears in any part of the string and is definitely more than 5 digits all the time and i want to give that