As an example I have this vector
c("qw;erty;qwert;qwe;", "ty;qwert;qw")
How can I use sub
function or any other to replace first occurrences of ";" from the end of the line with "\t" so the result will be c("qw;erty;qwert;qwe\t", "ty;qwert\tqw")
?
We can try
sub(";([^;]*)$", "\t\\1", str1)
#[1] "qw;erty;qwert;qwe\t" "ty;qwert\tqw"
str1 <- c("qw;erty;qwert;qwe;", "ty;qwert;qw")