rx_not: Ensure that the parameter does not follow.

View source: R/rules.R

rx_notR Documentation

Ensure that the parameter does not follow.

Description

This expression uses a negative lookahead to ensure the value given does not follow the previous verbal expression, perl = TRUE is required. For example, if you were to look for the letter q but not the letter u you might translate this to, "find the letter q everytime the letter u does not come after it".

Usage

rx_not(.data = NULL, value)

Arguments

.data

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

value

Value to ensure absence of

References

Negative lookahead: https://www.regular-expressions.info/lookaround.html

Examples

rx_not(value = "FEB-28")

# construct expression
x <- rx() %>%
  rx_start_of_line() %>%
  rx_find('FEB-29') %>%
  rx_not("FEB-28")

# create a string
string <- c("FEB-29-2017", "FEB-28-2017")

# extract matches, perl = TRUE is required for negative lookahead
regmatches(string, regexpr(x, string, perl = TRUE))

# another example
rx() %>%
  rx_find("q") %>%
  rx_not("u") %>%
  grepl(x = c("qu", "qa", "qq", "q", "q u"), perl = TRUE)


RVerbalExpressions documentation built on May 29, 2024, 6:47 a.m.