R regex find last occurrence of delimiter

后端 未结 4 1180
情深已故
情深已故 2020-12-06 13:58

I\'m trying to get the ending for email addresses (ie .net, .com, .edu, etc.) but the portion after the @ can have multiple periods.

library(stringi)

stri         


        
4条回答
  •  萌比男神i
    2020-12-06 14:30

    A solution using basic regex, assuming df1$X2 is a character vector:

    df1 <- cbind(df1, X3 = regmatches(df1$X2, regexpr('\\.[A-Z|a-z]*$', df1$X2)))
    df1$X3 <- gsub("\\.", "", df1$X3)
    

提交回复
热议问题