I'm trying to separate a messy free text field in which full names have been split by multiple delimiters. I've been able to split these into first names and surnames using the separate() function. However, the positive lookahead regex I've used leaves the delimitor in the surname. Is there an efficient way this could be automatically removed?
Example:
library(tibble)
library(tidyr)
mydf <- tribble(
~Name,
"Ben,Smith",
"Amy:White",
"Mark|Williams"
)
mydf_split <- mydf %>% separate(Name, c("first_name","surname"), sep = '(?=,|\\:|\\|)')
This returns the following dataframe.
first_name surname
1 Ben ,Smith
2 Amy :White
3 Mark |Williams
I would like to remove the , :, and | from the beginning of the surnames.