x <- c(aca1="acacaca", aca2="gaca", noaca="actgggca", na=NA)
regextr2(x, "(?a)(?cac?)")
gregextr2(x, "(?a)(?cac?)")
regextr2(x, "(?a)(?cac?)", capture_groups=TRUE)
gregextr2(x, "(?a)(?cac?)", capture_groups=TRUE)
# substitution - note the different replacement strings:
`gregextr2<-`(x, "(?a)(?cac?)", value=list(c("!", "?"), "#"))
# references to capture groups can only be used in gsub and sub:
gsub2(x, "(?a)(?cac?)", "{$1}{$2}")
regextr2(x, "(?a)(?cac?)") <- "\U0001D554\U0001F4A9"
print(x) # x was modified 'in-place'
Run the code above in your browser using DataLab