re2_which: Select strings that match, or find their positions

View source: R/RcppExports.R

re2_whichR Documentation

Select strings that match, or find their positions

Description

re2_subset returns strings that match a pattern. re2_which is equivalent to grep(pattern, x). It returns position of string that match a pattern. Vectorized over string and pattern. For the equivalent of grepl(pattern, x) see re2_detect.

Usage

re2_which(string, pattern)

re2_subset(string, pattern)

Arguments

string

A character vector, or an object which can be coerced to one.

pattern

Character string containing a regular expression, or a pre-compiled regular expression (or a vector of character strings and pre-compiled regular expressions).
See re2_regexp for available options.
See re2_syntax for regular expression syntax.

Value

re2_subset returns a character vector, and re2_which returns an integer vector.

See Also

re2_regexp for options to regular expression, re2_syntax for regular expression syntax, and re2_detect to find presence of a pattern (grep).

Examples

color <- c("yellowgreen", "steelblue", "GOLDENROD", "forestgreen")
re2_which(color, "o")
re2_subset(color, "o")

re2_which(c("x", "y", NA, "foo", ""), ".")
re2_subset(c("x", "y", NA, "foo", ""), ".")

# Use precompiled regexp
re <- re2_regexp("[a-z]")
re2_which(color, re)
re2_subset(color, re)

re <- re2_regexp("[a-z]", case_sensitive = FALSE)
re2_which(color, re)
re2_subset(color, re)

# Vector of patterns
re2_which(color, c("^o", "bl.e$", re, "$"))

re2 documentation built on March 29, 2022, 5:05 p.m.