Learn R Programming

reportr (version 1.0.0)

infix: Test a character vector for a match against a regular expression

Description

Test whether the elements of a character vector match, or don't match, a Perl regular expression.

Usage

X %~% Y
X %!~% Y

Arguments

X
A character vector to test for matches.
Y
A character vector of length one representing a Perl regular expression to match against.

Value

  • For %~%, TRUE for each element of X which matches the regular expression described by Y, and FALSE for every other element. For %!~%, the opposite.

Details

%~% is infix shorthand for regexpr(Y,X,perl=TRUE) != -1.

See Also

regexpr

Examples

Run this code
c("foo", "foo bar") %~% "\\w+\\s+(\\w+)?"  # c(FALSE, TRUE)
c("foo", "foo bar") %!~% "\\w+\\s+(\\w+)?"  # c(TRUE, FALSE)

Run the code above in your browser using DataLab