x <- c("3818119", "0M11936", "0X11087", "0T05060") sub("^0([[:alpha:]])", "\\1", x) sub("^0([A-Z])", "\\1", x) sub("^0(?=[A-Z])", "", x, perl=TRUE)
Standard input is empty
[1] "3818119" "M11936" "X11087" "T05060" [1] "3818119" "M11936" "X11087" "T05060" [1] "3818119" "M11936" "X11087" "T05060"