[R] Help with regular expressions.

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Tue Feb 9 03:29:12 CET 2021


I want to deal with strings of the form "a.b.c" and to change (using
sub() or whatever is appropriate) the second "." to a "-", i.e. to
change "a.b.c" to "a.b-c".  I want to leave the first "." as-is.

I guess I could do a gsub(), changing all "."s to "-"s, and then do
a sub() changing the first "-" back to a ".".  But this seems very
kludgy.  There must be a sexier way.  Mustn't there?  Is there regular
expression syntax for picking out the second occurence of a particular
string?

cheers,

Rolf Turner

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list