This is the approach I use in qdap:
Using qdap:
library(qdap) genXtract(txt, "this", "that") ## > genXtract(txt, "this", "that") ## this : that1 this : that2 this : that3 ## " and " " goes with " " is a long way from "
Without adding a package:
regmatches(txt, gregexpr("(?<=this).*?(?=that)", txt, perl=TRUE)) ## > regmatches(txt, gregexpr("(?<=this).*?(?=that)", txt, perl=TRUE)) ## [[1]] ## [1] " and " " goes with " " is a long way from "
Tyler rinker
source share