On Sat, Jan 31, 2009 at 4:46 PM, Wacek Kusnierczyk <waclaw.marcin.kusnierc...@idi.ntnu.no> wrote: > David Hajage wrote: >> Thank you, it's perfect. >> > > to extend the context, if you were to solve the problem in perl, the > regex below would work in perl 5.10, but not in earlier versions of > perl; another approach is to replace the unwanted leading characters > with equally many replacement characters at once. > > $string = 'aabaab'; > > # perl 5.10 > $string =~ s/a|(*COMMIT)(*FAIL)/c/g > # $string is 'ccbaab' > > # any recent perl > $string =~ s/^a*/'c' x length $&/e; > # $string is 'ccbaab' > > i don't know how (if) the latter could be done in r.
This seems quite analogous: library(gsubfn) s <- "aabaab" gsubfn("^a*", ~ paste(rep("c", nchar(x)), collapse = ""), s)[[1]] ______________________________________________ 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.