re2_extract(string, pattern, anchor = UNANCHORED, parallel = FALSE, grain_size = 1e+05, ...)re2_extract_all(string, pattern, anchor = UNANCHORED, parallel = FALSE, grain_size = 1e+05, ...)
UNANCHORED
re2
re2_extract
, and a list for re2_extract_all
.
Extract matching patterns from a string. Vectorised over string and pattern.
re2_extract("yabba dabba doo", "(.)")[1] "y"re2_extract_all("yabba dabba doo", "(.)")[[1]] [1] "y" "a" "b" "b" "a" " " "d" "a" "b" "b" "a" " " "d" "o" "o"str <- c("Aster", "Azalea x2", "Baby's Breath", "Bellflower") re2_extract(str, "\\d")[1] NA "2" NA NAre2_extract(str, "[a-z]+")[1] "ster" "zalea" "aby" "ellflower"re2_extract(str, "\\b\\w{1,3}\\b")[1] NA "x2" "s" NA# Extract all matches re2_extract_all(str, "[A-Za-z]+")[[1]] [1] "Aster" [[2]] [1] "Azalea" "x" [[3]] [1] "Baby" "s" "Breath" [[4]] [1] "Bellflower"re2_extract_all(str, "\\b\\w{1,3}\\b")[[1]] character(0) [[2]] [1] "x2" [[3]] [1] "s" [[4]] character(0)re2_extract_all(str, "\\d")[[1]] character(0) [[2]] [1] "2" [[3]] character(0) [[4]] character(0)
re2_match
to extract matched groups.