Skip to contents

Escapes special for regex characters conditionally

  • fixed - Match pattern string as it is within the target vector

  • begins - Match pattern string as it is in the beggining of the target vector

  • trim_begins - Match pattern string as it is in the beginning of the target vector ignoring preceding white-spaces

  • ends - Match pattern string as it is in the end of the target vector

  • trim_ends - Match pattern string as it is in the end of the target vector ignoring leading white-spaces

  • exact - Match pattern string exactly (i.e., match equal strings)

  • trim_exact - Match pattern string exactly (i.e., match equal strings) ignoring surrounding white-spaces

  • regex - Match regex pattern

Usage

escape_regex_for_types(
  patterns,
  types,
  escape_fixed = FALSE,
  escape_begins = TRUE,
  escape_ends = TRUE,
  escape_all_if_multiple_types = TRUE
)

Arguments

patterns

character vector

types

character vector of the same length as strings with instructions whether and how to to escape regex characters. Options are:

escape_fixed

Whether to escape strings for 'fixed' and 'exact' types in case all types are the same (length(unique(types)) == 1). The "trim_exact" types get trimed if not escaped. Otherwise if types heterogenious

escape_begins

Whether to escape string for 'begins' type

escape_ends

Whether to escape string for 'ends' type

escape_all_if_multiple_types

If types are multiple this applies to all esapes options

Value

string with all special to regex characters escaped