fork(1) download
  1. regex.escape <- function(string) {
  2. gsub("([][{}()+*^${|\\\\?.])", "\\\\\\1", string)
  3. }
  4.  
  5. sort.by.length.desc <- function (v) v[order( -nchar(v)) ]
  6.  
  7. A <- c("This :/ :/ :) ^^","is :/ ^^", "weird^^ :)")
  8. B <- c(":)",":/","^^")
  9.  
  10. B <- sort.by.length.desc(B)
  11. pattern <- paste(regex.escape(B), collapse="|")
  12. regmatches(A, gregexpr(pattern, A))
Success #stdin #stdout 0.25s 39328KB
stdin
Standard input is empty
stdout
[[1]]
[1] ":/" ":/" ":)" "^^"

[[2]]
[1] ":/" "^^"

[[3]]
[1] "^^" ":)"