re2r (version 0.2.0)

re2_locate: Locate the position of patterns in a string.

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.

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.

Examples

Run this code
# NOT RUN {
re2_locate("yabba dabba doo", "d")

fruit <- c("apple", "banana", "pear", "pineapple")
re2_locate(fruit, "$")
re2_locate(fruit, "a")
re2_locate(fruit, "e")
re2_locate(fruit, c("a", "b", "p", "p"))

re2_locate_all(fruit, "a")
re2_locate_all(fruit, "e")
re2_locate_all(fruit, c("a", "b", "p", "p"))

# Find location of every character
re2_locate_all(fruit, "\\P{M}")

# }

Run the code above in your browser using DataLab