re2_match(string, pattern, anchor = UNANCHORED, parallel = FALSE, grain_size = 1e+05, ...)re2_match_all(string, pattern, anchor = UNANCHORED, parallel = FALSE, grain_size = 1e+05, ...)
UNANCHORED
re2
re2_match
, a character matrix. First column
is the complete match, followed by one column
for each capture group with names.
For re2_match_all
, a list of
character matrices.
Find matched groups from strings.
strings <- c("Gym: 627-112-1433", "Apple x2", "888 888 8888", "This is a test.", "627-112-1433 223-343-2232") phone <- "([2-9][0-9]{2})[- .](?P<second>[0-9]{3})[- .]([0-9]{4})" re2_extract(strings, phone)[1] "627-112-1433" NA "888 888 8888" NA "627-112-1433"re2_match(strings, phone).match .1 second .3 [1,] "627-112-1433" "627" "112" "1433" [2,] NA NA NA NA [3,] "888 888 8888" "888" "888" "8888" [4,] NA NA NA NA [5,] "627-112-1433" "627" "112" "1433"re2_extract_all(strings, phone)[[1]] [1] "627-112-1433" [[2]] character(0) [[3]] [1] "888 888 8888" [[4]] character(0) [[5]] [1] "627-112-1433" "223-343-2232"re2_match_all(strings, phone)[[1]] .match .1 second .3 [1,] "627-112-1433" "627" "112" "1433" [[2]] .match .1 second .3 [[3]] .match .1 second .3 [1,] "888 888 8888" "888" "888" "8888" [[4]] .match .1 second .3 [[5]] .match .1 second .3 [1,] "627-112-1433" "627" "112" "1433" [2,] "223-343-2232" "223" "343" "2232"regexp = re2("test",case_sensitive = FALSE) re2_match("TEST", regexp).match [1,] "TEST"# differences from stringi # This kind of repeating capturing group works differently. re2_match("aasd", "(a*)+").match .1 [1,] "aa" "aa"stringi::stri_match("aasd", regex = "(a*)+")[,1] [,2] [1,] "aa" ""# In stringi, "" empty search patterns return NA. # In re2r, empty search patterns will match # empty string. re2_match("abc", "").match [1,] ""stringi::stri_match("abc", regex = "")Warning message: empty search patterns are not supported[,1] [1,] NA