match_pattern {chinese.misc} | R Documentation |
Extract Strings by Regular Expression Quickly
Description
Given a pattern and a character vector, the function will extract
parts of these characters that match
the pattern. It is simply a wrapper of regmatches
.
Usage
match_pattern(pattern, where, vec_result = TRUE, perl = FALSE)
Arguments
pattern |
a length 1 regular expression to be matched. |
where |
a character vector, each of its elements may or may not have parts that match the specified pattern. |
vec_result |
should be |
perl |
default is |
Value
a character vector or a list. If an element in where
is NA
, the result
corresponds to this element is character(0)
.
Examples
p <- "x.*?y"
x <- c("x6yx8y", "x10yx30y", "aaaaaa", NA, "x00y")
y <- match_pattern(p, x)
y <- match_pattern(p, x, vec_result = FALSE)