
Last chance! 50% off unlimited learning
Sale ends in
grep
and regexpr
.
x %~% rx x %!~% rx x %~*% rx x %!~*% rx
x %~+% rx x %!~+% rx
%~%
: gives a logical vector indicating which elements of x
match the regular expression rx
. %!~%
is the negation of
%~%
%~*%
: gives a single logical indicating if all the elements
of x
are matching the regular expression rx
. %!~*%
is the
negation of %~*%
.%~+%
: gives a single logical indicating if any
element of x
matches the regular expression rx
. %!~+%
is the negation of %~+%
.%~|%
for regular expression filters txt <- c("arm","foot","lefroo", "bafoobar")
txt %~% "foo"
txt %!~% "foo"
txt %~*% "foo"
txt %~+% "foo"
txt %!~*% "foo"
txt %!~+% "foo"
txt %~% "[a-z]"
txt %!~% "[a-z]"
txt %~*% "[a-z]"
txt %~+% "[a-z]"
txt %!~*% "[a-z]"
txt %!~+% "[a-z]"
cols <- colors()
cols[ cols %~% "^blue" ]
# see also %~|%
## needs perl regular expression for the \\d, see %but%
with( options( operators.regexpr = "p" ), {
cols[ cols %!~% "\\d$" ]
} )
Run the code above in your browser using DataLab