我想用适当的电子邮件格式验证(选择)数据库。
SO相关帖子here
示例:选择适当的格式:
example.data <- c("tint@tint.com","mailto:tint@tint.com","@tint.com",
"tint@","tint.tint.com",
"orange.com","orange@orange","orange@orange.com",
"e-mail: k-supra@k-supra.com","mailto:%20k-supra@k-supra.com")
desired.out <- c("tint@tint.com","mailto:tint@tint.com","orange@orange.com",
"k-supra@k-supra.com","k-supra@k-supra.com")
有人会分享工作解决方案吗?感谢。
答案 0 :(得分:1)
你可以尝试
v1 <- grep('^[^@]+@[^@]+\\.[^.]+$', example.data, value=TRUE)
v1
#[1] "tint@tint.com" "mailto:tint@tint.com"
#[3] "orange@orange.com" "e-mail: k-supra@k-supra.com"
#[5] "mailto:%20k-supra@k-supra.com"
要清理字符串,可能是
sub('^[^:]+:( |%\\d+)?', '', v1)
#[1] "tint@tint.com" "tint@tint.com" "orange@orange.com"
#[4] "k-supra@k-supra.com" "k-supra@k-supra.com"
grep('^[^@]+@[^@]+\\.[^.]+$', 'bill.gates@outlook.com', value=TRUE)
#[1] "bill.gates@outlook.com"