fork download
  1. character_vector <- c("<br>Hello</br>", "I want to keep this <important text> and <string?>")
  2. exclude <- c("important text", "string?")
  3. regex.escape <- function(string) {
  4. gsub("([][{}()+*^$|\\\\?.])", "\\\\\\1", string)
  5. }
  6. gsub(paste0("<(?!(?:", paste(regex.escape(exclude), collapse="|"), ")>)[^>]*>"), "", character_vector, perl=TRUE)
Success #stdin #stdout 0.23s 39748KB
stdin
Standard input is empty
stdout
[1] "Hello"                                             
[2] "I want to keep this <important text> and <string?>"