Created
June 22, 2014 01:15
-
-
Save wush978/1de5f8027fc0e6da682a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gregexpr.extract_subpattern <- function(pattern, text, pattern.name) { | |
r <- gregexpr(pattern, text, perl=TRUE) | |
sapply(seq_along(r), function(i) { | |
if (r[[i]] == -1) return("") | |
a <- attributes(r[[i]]) | |
stopifnot(isTRUE(all.equal(pattern.name, a$capture.names))) | |
substring(text[i], a$capture.start, a$capture.start + a$capture.length - 1) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment