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
.math.ethz.ch >Sent: Wednesday, October 5, 2011 1:56 PM >Subject: [R] help with regexp > >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', &

[R] help with regexp

2011-10-05 Thread Jannis
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' parts of these strings? Some try from my side yielded no r

[R] R: help with regexp mass substitution

2009-10-05 Thread Luca Braglia
Mmm, just Friday ... :) Thank you jim & gabor > -Messaggio originale- > Da: jim holtman > [mailto:jholt...@gmail.com] > Inviato: venerdì 2 ottobre 2009 > 14.12 > A: Luca Braglia > Cc: r-help@r-project.org > Oggetto: Re: [R] help with > regexp mass subst

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"

[R] help with regexp mass substitution

2009-10-02 Thread Luca Braglia
Hello * i have to rename a lot of variables, and, given that they have regular name constructs, I would like to use regexps. Here's a dump of my head(names(df)) varnames <- c("id.quest", "txt.1.3", "col1.1.3", "col2.1.3", "col3.1.3", "col4.1.3", "col5.1.3", "txt.2.3", "col1.2.3", "col2.2.3", "