Re: [R] help with regexp

2011-10-06 Thread Jannis
Thanks to all who replied! With all these possible solutions it will be hard to find the best one :-). --- Gabor Grothendieck schrieb am Mi, 5.10.2011: > Von: Gabor Grothendieck > Betreff: Re: [R] help with regexp > An: "Jannis" > CC: r-h...@stat.math.ethz.ch > Da

Re: [R] help with regexp

2011-10-05 Thread Gabor Grothendieck
On Wed, Oct 5, 2011 at 7:56 AM, Jannis wrote: > Dear list memebers, > > > I am stuck with using regular expressions. > > > Imagine I have a vector of character strings like: > > test <- c('filename_1_def.pdf', 'filename_2_abc.pdf') > > How could I use regexpressions to extract only the 'def'/'abc'

Re: [R] help with regexp

2011-10-05 Thread Eik Vettorazzi
Hi Jannis, just use the backreferences in gsub, see ?gsub, -> replacement test <- c('filename_1_def.pdf', 'filename_2_abc.pdf') gsub(".*_([A-z]+)\\.pdf", "\\1", test) hth. Am 05.10.2011 13:56, schrieb Jannis: > Dear list memebers, > > > I am stuck with using regular expressions. > > > Imagi

Re: [R] help with regexp

2011-10-05 Thread Albert-Jan Roskam
Hello!   library(gsubfn) test <- c('filename_1_def.pdf', 'filename_2_abc.pdf') gsubfn("(.+_)([a-z]+)(\\.pdf)", "\\2", test) Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public

Re: [R] help with regexp mass substitution

2009-10-02 Thread Gabor Grothendieck
dot (.) matches anything so be sure to escape it so that it only matches a literal dot in your regular expression. On Fri, Oct 2, 2009 at 5:39 AM, Luca Braglia wrote: > Hello * > > i have to rename a lot of variables, and, given that they have regular name > constructs, I would like to use regex

Re: [R] help with regexp mass substitution

2009-10-02 Thread jim holtman
You need perl=TRUE: gsub("^col(\\d{1,2}).(\\d{1,2}).(\\d{1,2})", "dom\\3.rig\\2.col\\1", varnames, perl=TRUE) [1] "id.quest""txt.1.3" "dom3.rig1.col1" "dom3.rig1.col2" "dom3.rig1.col3" "dom3.rig1.col4" "dom3.rig1.col5" [8] "txt.2.3" "dom3.rig2.col1" "dom3.rig2.col2"