To extract a substring from a string according to a pattern, you can use the following functions:
string = c("G1:E001", "G2:E002", "G3:E003")
substring(string, 4)
[1] "E001" "E002" "E003"
This extracts the string from the fourth character which is true in the above vector.
substring(string, regexpr(":", string) + 1)
[1] "E001" "E002" "E003"
You can also use the separate function from the tidyr package as follows:
library(dplyr)
library(tidyr)
library(purrr)
df <- data.frame(string)
df %>%
separate(string, into = c("pre", "post")) %>%
pull("post")
[1] "E001" "E002" "E003"
You can also use the str_extract function from the stringr package as follows:
library("stringr")
str_extract(string = string, pattern = "E[0-9]+")
[1] "E001" "E002" "E003"