Learn R Programming

RVerbalExpressions (version 0.0.0.9000)

end_of_line: Match the expression only if it appears till the end of the line.

Description

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.

Usage

end_of_line(.data = NULL, enable = TRUE)

Arguments

.data

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

enable

Whether to enable this behavior, defaults to TRUE

References

Anchors: https://www.regular-expressions.info/anchors.html

Examples

Run this code
# NOT RUN {
end_of_line(enable = TRUE)
end_of_line(enable = FALSE)
end_of_line("abc", enable = TRUE)

# create expression
x <- start_of_line(FALSE) %>%
  find("apple") %>%
  end_of_line()

grepl(x, "apples") # should be false
grepl(x, "apple")  # should be true

# }

Run the code above in your browser using DataLab