I'm trying to extract names from a list produced by SharePoint.
Each item in the list contains at least one name and a numeric id which varies in length.
The format of the list looks like:
all_projects %>%
select(contact_names)
A tibble: 116 x 1
contact_names
<chr>
1 last_name, first_name;#6903;#last_name, first_name;#36606
2 last_name, first_name;#8585
3 ...
4 last_name, first_name;#14801
Using stringr
I've managed to get the numbers out with the following:
str_replace_all(string, pattern = ";#?\\d*", ";")
But it results in:
\"last_name, first_name;;last_name, first_name;\",
Which would be ok but for the double ;;
. Inserting a (""
) blank string str_replace_all(string, pattern = ";#?\\d*", "")
returns:
\"last_name, first_namelast_name, first_name;\",
Ideally I'd like to separate the first and last names into two columns.
Any help greatly appreciated.