R/rules.R
rx_end_of_line.Rd
Control whether to match the expression only if it appears till
the end of the line. Basically, append a $
to the end of the
expression. The dollar sign is considered an anchor and matches the
position of characters. It can be used to "anchor" the regex match at a
certain position, in this case the dollar sign matches right after the last
character in the string.
rx_end_of_line(.data = NULL, enable = TRUE)
.data | Expression to match, typically pulled from the pipe |
---|---|
enable | Whether to enable this behavior, defaults to |
Anchors: https://www.regular-expressions.info/anchors.html
rx_end_of_line(enable = TRUE)#> [1] "$"rx_end_of_line(enable = FALSE)#> NULLrx_end_of_line("abc", enable = TRUE)#> [1] "abc$"# create expression x <- rx() %>% rx_start_of_line(FALSE) %>% rx_find("apple") %>% rx_end_of_line() grepl(x, "apples") # should be false#> [1] FALSE#> [1] TRUE