I'd like a regex for sub in R to substitute the characters in a string which follow the nth occurrence of ";" in that string, where n is a variable number passed to the regex.
stringA="a; b; c; d; e; f; g; h; i; j;"
stringB<-sub("^(;){4}.*", "", stringA)
##---------------^My attempt at a regular expression here-------
Desired output:
stringB
"a; b; c; d;"
See Question&Answers more detail:os