Re: [R] backreferences in gregexpr
On Sat, Nov 3, 2012 at 4:08 PM, Alexander Shenkin wrote: > On 11/2/2012 5:14 PM, Gabor Grothendieck wrote: > > On Fri, Nov 2, 2012 at 6:02 PM, Alexander Shenkin > wrote: > >> Hi Folks, > >> > >> I'm trying to extract just the backreferences from a regex. > >> > >>> temp = "abcd1234abcd1234" > >>> regmatches(temp, gregexpr("(?:abcd)(1234)", temp)) > >> [[1]] > >> [1] "abcd1234" "abcd1234" > >> > >> What I would like is: > >> [1] "1234" "1234" > >> > >> Note: I know I can just match 1234 here, but the actual example is > >> complicated enough that I have to match a larger string, and just want > >> to pass out the backreferenced portion. > >> > >> Any help greatly appreciated! > >> > > > > Try this: > > > >> library(gsubfn) > >> strapplyc(temp, "abcd(1234)") > > [[1]] > > [1] "1234" "1234" > > > > Thanks Gabor. Didn't find strapplyc in package gsubfun, but did find > strapply, and that worked well. > You must have an old version of the package. Time to upgrade. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com [[alternative HTML version deleted]] __ 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.
Re: [R] backreferences in gregexpr
On 11/2/2012 5:14 PM, Gabor Grothendieck wrote: > On Fri, Nov 2, 2012 at 6:02 PM, Alexander Shenkin wrote: >> Hi Folks, >> >> I'm trying to extract just the backreferences from a regex. >> >>> temp = "abcd1234abcd1234" >>> regmatches(temp, gregexpr("(?:abcd)(1234)", temp)) >> [[1]] >> [1] "abcd1234" "abcd1234" >> >> What I would like is: >> [1] "1234" "1234" >> >> Note: I know I can just match 1234 here, but the actual example is >> complicated enough that I have to match a larger string, and just want >> to pass out the backreferenced portion. >> >> Any help greatly appreciated! >> > > Try this: > >> library(gsubfn) >> strapplyc(temp, "abcd(1234)") > [[1]] > [1] "1234" "1234" > Thanks Gabor. Didn't find strapplyc in package gsubfun, but did find strapply, and that worked well. __ 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.
Re: [R] backreferences in gregexpr
HI, I am not sure whether this helps: temp1<-regmatches(temp, gregexpr("(?:abcd)(1234)", temp)) #your code substr(unlist(temp1),5,8) #[1] "1234" "1234" A.K. - Original Message - From: Alexander Shenkin To: r-help@r-project.org Cc: Sent: Friday, November 2, 2012 6:02 PM Subject: [R] backreferences in gregexpr Hi Folks, I'm trying to extract just the backreferences from a regex. > temp = "abcd1234abcd1234" > regmatches(temp, gregexpr("(?:abcd)(1234)", temp)) [[1]] [1] "abcd1234" "abcd1234" What I would like is: [1] "1234" "1234" Note: I know I can just match 1234 here, but the actual example is complicated enough that I have to match a larger string, and just want to pass out the backreferenced portion. Any help greatly appreciated! Thanks, Allie __ 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. __ 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.
Re: [R] backreferences in gregexpr
On Fri, Nov 2, 2012 at 6:02 PM, Alexander Shenkin wrote: > Hi Folks, > > I'm trying to extract just the backreferences from a regex. > >> temp = "abcd1234abcd1234" >> regmatches(temp, gregexpr("(?:abcd)(1234)", temp)) > [[1]] > [1] "abcd1234" "abcd1234" > > What I would like is: > [1] "1234" "1234" > > Note: I know I can just match 1234 here, but the actual example is > complicated enough that I have to match a larger string, and just want > to pass out the backreferenced portion. > > Any help greatly appreciated! > Try this: > library(gsubfn) > strapplyc(temp, "abcd(1234)") [[1]] [1] "1234" "1234" -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ 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.
[R] backreferences in gregexpr
Hi Folks, I'm trying to extract just the backreferences from a regex. > temp = "abcd1234abcd1234" > regmatches(temp, gregexpr("(?:abcd)(1234)", temp)) [[1]] [1] "abcd1234" "abcd1234" What I would like is: [1] "1234" "1234" Note: I know I can just match 1234 here, but the actual example is complicated enough that I have to match a larger string, and just want to pass out the backreferenced portion. Any help greatly appreciated! Thanks, Allie __ 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.