Learn R Programming

RVerbalExpressions (version 0.0.0.9000)

maybe: Optionally match an expression.

Description

This expression uses a quantifier ? to optionally match things. Specifically, the question mark makes the preceding token in the regular expression optional.

Usage

maybe(.data = NULL, value)

Arguments

.data

Expression to append, typically pulled from the pipe %>%

value

Expression to optionally match

References

Quantifiers: https://www.regular-expressions.info/optional.html

Examples

Run this code
# NOT RUN {
maybe(value = "abc")

# create expression
x <- start_of_line() %>%
  maybe("abc") %>%
  end_of_line(enable = FALSE)

grepl(x, "xyz") # should be true

# }

Run the code above in your browser using DataLab