ore_ismatch: Does text match a regex?

ore_ismatchR Documentation

Does text match a regex?

Description

These functions test whether the elements of a character vector match a Oniguruma regular expression. The actual match can be retrieved using ore_lastmatch.

Usage

ore_ismatch(regex, text, keepNA = getOption("ore.keepNA", FALSE), ...)

X %~% Y

X %~~% Y

X %~|% Y

Arguments

regex

A single character string or object of class "ore".

text

A character vector of strings to search.

keepNA

If TRUE, NAs will be propagated from text into the return value. Otherwise, they evaluate FALSE.

...

Further arguments to ore_search.

X

A character vector or "ore" object. See Details.

Y

A character vector. See Details.

Details

The %~% infix shorthand corresponds to ore_ismatch(..., all=FALSE), while %~~% corresponds to ore_ismatch(..., all=TRUE). Either way, the first argument can be an "ore" object, in which case the second is the text to search, or a character vector, in which case the second argument is assumed to contain the regex. The %~|% shorthand returns just those elements of the text vector which match the regular expression.

Value

A logical vector, indicating whether elements of text match regex, or not.

See Also

ore_search

Examples

# Test for the presence of a vowel
ore_ismatch("[aeiou]", c("sky","lake"))  # => c(FALSE,TRUE)

# The same thing, in shorter form
c("sky","lake") %~% "[aeiou]"

# Same again: the first argument must be an "ore" object this way around
ore("[aeiou]") %~% c("sky","lake")

jonclayden/ore documentation built on Jan. 13, 2024, 2:54 a.m.