#' Exact
#'
#' ensure that pattern matches the entire pattern and not any substring
#'
#' @param pattern string specifying a search pattern. Pattern modifiers can
#' be used, such as \code{\link{exact}}
#'
#' @details
#' Simply wraps a patterns between \code{"^"} and \code{"$"} ensuring that
#' the regular expression matches the entire pattern.
#'
#' @note
#' This is a poor substitute for being implemented within \code{stringr}. See
#' \url{https://github.com/hadley/stringr/issues/55}
#'
#' @references
#' \url{https://github.com/hadley/stringr/issues/55}
#'
#' @export
exact <- function(pattern) {
if(
! class(pattern) == 'Pattern' ||
pattern@type == 'regex'
)
stop( "Exact only works for regex patterns" )
pattern@.Data <- paste0( "^", pattern, "$" )
pattern
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.