As the title says. I have a bunch of names and I need to add a comma after the first word that starts with a capital letter.
An example:
txt <- c( "de Van-Smith J", "van der Smith G.H.", "de Smith JW", "Smith JW")
The result should be:
[1] "de Van-Smith, J" "van der Smith, G.H." "de Smith, JW" "Smith, JW"
I have mainly been trying to use gsub()
and stringr::str_replace()
, but am stuggling with the regex, any advice would be appreciated.