Locate the position of patterns in a string.

Usage

re2_locate(string, pattern, parallel = FALSE, grain_size = 1e+05, ...)
re2_locate_all(string, pattern, parallel = FALSE, grain_size = 1e+05, ...)

Arguments

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

Value

For re2_locate, an integer matrix. First column gives start postion of match, and second column gives end position. For re2_locate_all a list of integer matrices.

Description

Locate the position of patterns in a string.If the match is of length 0, (e.g. from a special match like $) end will be one character less than start. Vectorised over string and pattern.

Examples

re2_locate("yabba dabba doo", "d")
start end [1,] 7 7
fruit <- c("apple", "banana", "pear", "pineapple") re2_locate(fruit, "$")
start end [1,] 6 5 [2,] 7 6 [3,] 5 4 [4,] 10 9
re2_locate(fruit, "a")
start end [1,] 1 1 [2,] 2 2 [3,] 3 3 [4,] 5 5
re2_locate(fruit, "e")
start end [1,] 5 5 [2,] NA NA [3,] 2 2 [4,] 4 4
re2_locate(fruit, c("a", "b", "p", "p"))
start end [1,] 1 1 [2,] 1 1 [3,] 1 1 [4,] 1 1
re2_locate_all(fruit, "a")
[[1]] start end [1,] 1 1 [[2]] start end [1,] 2 2 [2,] 4 4 [3,] 6 6 [[3]] start end [1,] 3 3 [[4]] start end [1,] 5 5
re2_locate_all(fruit, "e")
[[1]] start end [1,] 5 5 [[2]] start end [[3]] start end [1,] 2 2 [[4]] start end [1,] 4 4 [2,] 9 9
re2_locate_all(fruit, c("a", "b", "p", "p"))
[[1]] start end [1,] 1 1 [[2]] start end [1,] 1 1 [[3]] start end [1,] 1 1 [[4]] start end [1,] 1 1 [2,] 6 6 [3,] 7 7
# Find location of every character re2_locate_all(fruit, "\\P{M}")
[[1]] start end [1,] 1 1 [2,] 2 2 [3,] 3 3 [4,] 4 4 [5,] 5 5 [[2]] start end [1,] 1 1 [2,] 2 2 [3,] 3 3 [4,] 4 4 [5,] 5 5 [6,] 6 6 [[3]] start end [1,] 1 1 [2,] 2 2 [3,] 3 3 [4,] 4 4 [[4]] start end [1,] 1 1 [2,] 2 2 [3,] 3 3 [4,] 4 4 [5,] 5 5 [6,] 6 6 [7,] 7 7 [8,] 8 8 [9,] 9 9