regex - Remove escaping \n -


some data:

x <- c("town\ninfo@notus.com\n\n","\ninfo@notus.com\n","\ninfo@notus.com\n\n","\ninfo@notus.com\n","info@notus.com") 

this work there word before \n

gsub("\n","",x,fixed=t) 

this works if there isn't \n gives na

unlist(lapply(regmatches(x,gregexpr("(?<=\n).*",x,perl=true)), function(x) x[1])) 

edit: desired result:

rep("info@notus.com",5) 

use gsub.

gsub("(?s)^.*?\\n|\\n.*", "", x, perl=t) 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -