Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205491

How to replace some characters after the last dot with their lower cases

$
0
0

A simple question but I cannot solve it. I got a string like this mail address:

ma <- "something@somewhere.COM"

My goal is to get:

"something@somewhere.com"

So to put the to lower cases the part after the last dot. I've read this, this, so I tried:

gsub(".*\\.","\\L\\1", ma, perl = T) 
[1] "COM" # nope

Also something like:

library(gsubfn)
options(gsubfn.engine = "R")
gsubfn(".*\\.", ~ tolower(x), ma)
[1] "something@somewhere.COM" # nope

I'm quite confused because it seems I can fetch the part I want to replace:

gsub(".*\\.","", ma)
[1] "COM"

But I cannot replace it properly. If you can give an explaination with the solution, I'll gladly appreciate it, regex is not my strongest feature.


Viewing all articles
Browse latest Browse all 205491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>