Re: [R] regular expressions

From: Christos Hatzis <christos.hatzis_at_nuverabio.com>
Date: Wed, 12 Mar 2008 23:46:32 -0400

Try this one:

> gsub("^(plif)([a-z]*)", "\\1ONE", words)
[1] "plifONE" "plafboum" "ploufbang" "plifONE"

-Christos

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of GOUACHE David
> Sent: Wednesday, March 12, 2008 12:15 PM
> To: r-help_at_stat.math.ethz.ch
> Subject: [R] regular expressions
>
> Hello all,
>
> Still fighting with regular expressions and such, I am again stuck:
>
> Suppose I have a vector of character chains. In this vector,
> I wish to identify which character chains start with a given
> pattern, and then replace everything that comes after said pattern.
>
> Here is a quick example :
>
> words<-c("plifboum","plafboum","ploufbang","plifplaf")
>
> I want to end up with something like this:
>
> "plifONE","plafboum","ploufbang","plifONE"
>
> All I can produce so far is this :
> gsub("\\bplif.","ONE",words,perl=T)
>
> which turns out :
> "ONEboum","plafboum","ploufbang","ONEplaf"
>
> Thanks in advance for your help.
>
> David Gouache
>
> Arvalis - Institut du Végétal
>
> Station de La Minière
>
> 78280 Guyancourt
>
> Tel: 01.30.12.96.22 / Port: 06.86.08.94.32
>
>
>
>
> ______________________________________________
> R-help_at_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_at_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. Received on Thu 13 Mar 2008 - 03:47:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 13 Mar 2008 - 04:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive