Extract matching patterns from a string.

Usage

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, ...)

Arguments

string
a character vector
pattern
a character vector or pre-compiled regular expressions
anchor
see UNANCHORED
parallel
use multithread
grain_size
a minimum chunk size for tuning the behavior of parallel algorithms
...
further arguments passed to re2

Value

A character vector for re2_extract, and a list for re2_extract_all.

Description

Extract matching patterns from a string. Vectorised over string and pattern.

Examples

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 NA
re2_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)

See also

re2_match to extract matched groups.