fork download
  1. test_str <- "Made out of wood, a book can contain many pages that are used to transmit information."
  2.  
  3. my_regex <- "(?i)(?=(\\b(?:(?:\\w+\\W+){5}|^(?:\\w+\\W+){0,4})(?:\\bbooks?|\\bpages?)\\b(?:(?:\\W+\\w+){5}|(?:\\W+\\w+){0,4}$)))"
  4.  
  5. m <- gregexpr(my_regex, test_str, perl=TRUE)
  6. m <- lapply(m, function(i) {
  7. attr(i, "match.length") <- attr(i, "capture.length")
  8. i
  9. })
  10. regmatches(test_str, m)
Success #stdin #stdout 0.26s 39448KB
stdin
Standard input is empty
stdout
[[1]]
[1] "Made out of wood, a book can contain many pages that"   
[2] "a book can contain many pages that are used to transmit"