这是5个Twitter用户的描述。我们的目标是从每个字符串中提取电子邮件地址。
这是我尝试过的代码,它可以工作但可能有更好的方法。 我更愿意避免使用unlist()并使用regex一次完成。我看到其他关于Python/Perl/PHP的类似问题,但没有关于R的。 我知道我可以使用grep(..., perl = TRUE),但那不应该是唯一的方法。 如果能行,当然是有帮助的。
ds <- c("#MillonMusical | #PromotorMusical | #Diseñador | Contacto : ezequielife@gmail.com | #Instagram : Ezeqielgram | 01-11-11 | @_MillonMusical @flowfestar", "LipGLosSTudio by: SAndry RUbio Maquilladora PRofesional estudiande de diseño profesional de maquillaje artistico lipglosstudio@hotmail.com/", "Medico General Barranquillero radicado con su familia en Buenos Aires para iniciar Especialidad Medico Quirurgica. email jaenpavi@hotmail.com", "msn =
rdt031169@hotmail.comskype = ronaldotorres-br", "Aguante piscis / manuarias17@gmail.com buenos aires"
)
ds <- unlist(strsplit(ds, ' '))
ds <- ds[grep("mail.", ds)]
> print(ds)
[1] "\t\tezequielife@gmail.com" "lipglosstudio@hotmail.com/"
[3] "jaenpavi@hotmail.com" "rdt031169@hotmail.comskype"
[5] "/\t\tmanuarias17@gmail.com"
希望能将这个“rdt031169@hotmail.comskype”分开,也许要求其以.com或.com.ar结尾会更合理,这符合我的工作需求。
jilbex <- "[[:alnum:]]+\\@[[:alpha:]]+\\.com"; newex <- paste(jilbex,'(\\.(ar|bah))?',sep=''); ds2 <- c(ds,'you@here.com.ar');regmatches(ds2,regexpr(newex,ds2))
其中 "bah" 可能是您想要捕获的其他后缀。 - Frank