reverse the name string from extracting mail

I am looking for a script to extract name from email. and then reverse the name string for example email = ram.singh.tak@zzzz.com then extract ram.singh.tak from email and replace "." with space like ram singh tak and then mutate data frame with new column with reverse name like tak singh ram

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.ali@@ttt.com","nick.jone@ttt.com","liam.mak1@ttt.com","r.mush@ttt.com","dude.sink@ttt.com"))

separator = " "



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

I am trying to match name and name in email after extracting name from email and reverse of name in email . sometimes separator can be comma "," or "." or " "space in name column. thats why i am giving input parameter as separator for user

is there any solution updation for my code...???

the output be like below

image

what do you mean by this?

I ran your code and received output.
Perhaps your session needs restarting

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

I mean output is not coming , sorry