re2_split {re2} | R Documentation |
Split string based on pattern
Description
Vectorized over string and pattern.
Usage
re2_split(string, pattern, simplify = FALSE, n = Inf)
Arguments
string |
A character vector, or an object which can be coerced to one. |
pattern |
Character string containing a regular expression,
or a pre-compiled regular expression (or a vector of character
strings and pre-compiled regular expressions). |
simplify |
If FALSE, the default, return a list of string vectors. If TRUE, return a string matrix. |
n |
Number of string pieces to return. Default (Inf) returns all. |
Value
A list of string vectors or a string matrix. See option.
See Also
re2_regexp
for options to regular expression,
re2_syntax for regular expression syntax, and
re2_match
to extract matched groups.
Examples
panagram <- c(
"The quick brown fox jumps over the lazy dog",
"How vexingly quick daft zebras jump!"
)
re2_split(panagram, " quick | over | zebras ")
re2_split(panagram, " quick | over | zebras ", simplify = TRUE)
# Use compiled regexp
re <- re2_regexp("quick | over |how ", case_sensitive = FALSE)
re2_split(panagram, re)
re2_split(panagram, re, simplify = TRUE)
# Restrict number of matches
re2_split(panagram, " quick | over | zebras ", n = 2)
[Package re2 version 0.1.3 Index]