Learn R Programming

re2 (version 0.1.3)

re2_detect: Find the presence of a pattern in string(s)

Description

Equivalent to grepl(pattern, x). Vectorized over string and pattern. For the equivalent of grep(pattern, x) see re2_which.

Usage

re2_detect(string, pattern)

Value

A logical vector. TRUE if match is found, FALSE if not.

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.

See Also

re2_regexp for options to regular expression, re2_syntax for regular expression syntax, and re2_match to extract matched groups.

Examples

Run this code
## Character vector input
s <- c("barbazbla", "foobar", "not present here ")
pat <- "(foo)|(bar)baz"
re2_detect(s, pat)

## Use precompiled regexp
re <- re2_regexp("(foo)|(bAR)baz", case_sensitive = FALSE)
re2_detect(s, re)

Run the code above in your browser using DataLab