Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

expect_match

Does a string match a regular expression?


Description

Does a string match a regular expression?

Usage

expect_match(
  object,
  regexp,
  perl = FALSE,
  fixed = FALSE,
  ...,
  all = TRUE,
  info = NULL,
  label = NULL
)

Arguments

object

Object to test.

Supports limited unquoting to make it easier to generate readable failures within a function or for loop. See quasi_label for more details.

regexp

Regular expression to test against.

perl

logical. Should Perl-compatible regexps be used?

fixed

logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.

...

Arguments passed on to base::grepl

ignore.case

if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

useBytes

logical. If TRUE the matching is done byte-by-byte rather than character-by-character. See ‘Details’.

all

Should all elements of actual value match regexp (TRUE), or does only one need to match (FALSE)

info

Extra information to be included in the message. This argument is soft-deprecated and should not be used in new code. Instead see alternatives in quasi_label.

label

Used to customise failure messages. For expert use only.

Details

expect_match() is a wrapper around grepl(). See its documentation for more detail about the individual arguments.

See Also

Examples

expect_match("Testing is fun", "fun")
expect_match("Testing is fun", "f.n")

## Not run: 
expect_match("Testing is fun", "horrible")

# Zero-length inputs always fail
expect_match(character(), ".")

## End(Not run)

testthat

Unit Testing for R

v3.0.2
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], RStudio [cph, fnd], R Core team [ctb] (Implementation of utils::recover())
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.