So I have this list of names:
names <- c("stewart,pat", "peterson,greg")
from which I extract only the lastname,firstname
items with the following regular expression:
myregexpr <- "(\\w+),(\\w+)?"
str_view(str_extract_all(names, myregexpr), myregexpr)
This yields a view like:
stewart,pat
peterson,greg
My question: Is there a way for me to write the regular expression such that the result would instead look like:
pat_stewart
greg_peterson
i.e. where the result of is first_last
? I believe there is a way to do it as I've seen on other, similar questions. I've tried:
myregexpr <- "(\\w+),(\\w+)?\\2_\\1"
but that returns only `character(0)'. I've attempted many versions - some of which crash R studio. Any ideas?