Learn R Programming

lares (version 5.1.0)

grepm: Pattern Matching for Any or All Multiple Matches

Description

This function returns a boolean vector of the same length as `x`, each element of which is the result of applying the `type` of matches to the corresponding element of `x`, using regular expressions.

Usage

grepm(pattern, x, type = "all", ...)

Arguments

pattern

character string containing a regular expression (or character string for fixed = TRUE) to be matched in the given character vector. Coerced by as.character to a character string if possible. If a character vector of length 2 or more is supplied, the first element is used with a warning. Missing values are allowed except for regexpr, gregexpr and regexec.

x

a character vector where matches are sought, or an object which can be coerced by as.character to a character vector. Long vectors are supported.

type

Character. Type of match. Choose one of: any, all

...

Additional arguments to pass to grepl

Value

Boolean of same length as x

Examples

Run this code
# NOT RUN {
x <- c(123, 876, 18761)
patterns <- c(1, 2)
grepm(patterns, x, type = "any")
grepm(patterns, x, type = "all")
# }

Run the code above in your browser using DataLab