This expression uses a quantifier ?
to optionally
match things. Specifically, the question mark makes the preceding token in
the regular expression optional.
maybe(.data = NULL, value)
.data | Expression to append, typically pulled from the pipe |
---|---|
value | Expression to optionally match |
Quantifiers: https://www.regular-expressions.info/optional.html
maybe(value = "abc")#> [1] "(?:abc)?"# create expression x <- start_of_line() %>% maybe("abc") %>% end_of_line(enable = FALSE) grepl(x, "xyz") # should be true#> [1] TRUE