Skip to content
Prev 387138 / 398503 Next

Help with regular expressions.

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