fork download
  1. library(stringr)
  2. my_string <- "\r\nContent: base64\r\n\r\nDBhHB\r\nDGlV\r\nPAAHJ\r\nAwQU\r\n"
  3. pat <- "(?m)^\\S+(?:\\R\\S+)*$"
  4. pat_PCRE <- "(*ANYCRLF)(?m)^\\S+(?:\\R\\S+)*$"
  5.  
  6. unlist(str_extract_all(my_string, pat))
  7. unlist(regmatches(my_string, gregexpr(pat_PCRE,my_string, perl=TRUE)))
  8. ## => [1] "DBhHB\r\nDGlV\r\nPAAHJ\r\nAwQU"
  9.  
  10. my_string <- "\r\nNot This\r\n\r\nKeepThis\r\nKeepThis\r\nNot This\r\nKeepThis\r\n"
  11. unlist(str_extract_all(my_string, pat))
  12. unlist(regmatches(my_string, gregexpr(pat_PCRE,my_string, perl=TRUE)))
  13. ## => [1] "KeepThis\r\nKeepThis" "KeepThis"
Success #stdin #stdout 0.28s 42748KB
stdin
Standard input is empty
stdout
[1] "DBhHB\r\nDGlV\r\nPAAHJ\r\nAwQU"
[1] "DBhHB\r\nDGlV\r\nPAAHJ\r\nAwQU"
[1] "KeepThis\r\nKeepThis" "KeepThis"            
[1] "KeepThis\r\nKeepThis" "KeepThis"