Q: Getting error while validating names and names in email column I am trying to make it dynamic so that it will detect separator dynamically by user provided separator
df <-  data.frame(name= c("ali, wing sam","nick, jone","mak, liam","r, mush","sink, dude"),
                  Email = c("sam.wing.ali1@xyz.com","nick.jone @xyz.com","liam.mak@xyz.com","r.mush@xyz.com","dude.sink@xyz.com"))

separator = ", "

df %>% 
  mutate(across(c(name,Email), tolower), 
         email_name1 = str_extract(Email, '.*(?=@)'),
         email_name = str_extract(Email, '.*?(?=@)')) %>%
  separate(col = email_name, into = c('f','s','l'), sep = '\\.', fill = 'right') %>%
  mutate(l = replace_na(l,''), 
         email_name_rev = str_squish(str_c(l,s,f, sep = "."))) %>%
  mutate(match1 = +(name == email_name_rev | name == email_name1)) %>%
  select(-c(f,s,l))


what i am doing wrong in my code.....??
now I am getting the output be like below

A: You can split the name and use grepl to test if all the subnames are in the Email.
mapply(function(x, y) all(sapply(paste0("\\b",x,"\\b"), grepl, y)),
 strsplit(df$name, " "), df$Email)
#[1]  TRUE  TRUE FALSE  TRUE  TRUE

And for gsub and rev and strsplit for the mail names:
(x <- gsub(".", " ", sub("@.*", "", df$Email), fixed = TRUE))
#[1] "sam wing ali" "nick jone"    "liam mak1"    "r mush"       "dude sink"   

sapply(strsplit(x, " ", TRUE), function(y) paste(rev(y), collapse = " "))
#[1] "ali wing sam" "jone nick"    "mak1 liam"    "mush r"       "sink dude"   


A: Try this :
library(tidyverse)


separator = ", "

df %>% 
  mutate(across(c(name,Email), tolower), 
         email_name1 = str_extract(Email, '.*(?=@)'),
         email_name1 = str_replace_all(email_name1, "[.@]", separator),
         email_name = str_extract(Email, '.*?(?=@)')) %>%
  separate(col = email_name, into = c('f','s','l'), sep = '\\.', fill = 'right') %>%
  mutate(l = replace_na(l,''), 
         email_name_rev = trimws(str_c(l,s,f, sep = separator), whitespace = separator)) %>%
  mutate(match1 = +(name == email_name_rev | name == email_name1)) %>%
  select(-c(f,s,l))


#           name                 Email     email_name1  email_name_rev match1
#1 ali, wing sam sam.wing.ali1@xyz.com sam, wing, ali1 ali1, wing, sam      0
#2    nick, jone    nick.jone @xyz.com     nick, jone      jone , nick      0
#3     mak, liam      liam.mak@xyz.com       liam, mak       mak, liam      1
#4       r, mush        r.mush@xyz.com         r, mush         mush, r      1
#5    sink, dude     dude.sink@xyz.com      dude, sink      sink, dude      1


*

*No need to write separate mutate for each line.

*Add fill = 'right' in separate to avoid getting the warning.

*You have double at ('@@') in first email not sure if it is how your real data is or this is just a typo. I have included the code to remove it.

