Skip to content

Instantly share code, notes, and snippets.

@gmbecker
Created December 17, 2015 21:58
Show Gist options
  • Save gmbecker/13ed46061c6465c7e069 to your computer and use it in GitHub Desktop.
Save gmbecker/13ed46061c6465c7e069 to your computer and use it in GitHub Desktop.
happyfun = function(pat, txt) {
m = gregexpr(pat, txt, perl=TRUE)[[1]];
t = attr(m, "capture.start");
mapply(function(st, end) substr(txt, st, end),
st = t,
end = t+attr(m, "capture.length")-1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment