re2_split: Split string based on pattern

View source: R/RcppExports.R

re2_splitR Documentation

Split string based on pattern


Vectorized over string and pattern.


re2_split(string, pattern, simplify = FALSE, n = Inf)



A character vector, or an object which can be coerced to one.


Character string containing a regular expression, or a pre-compiled regular expression (or a vector of character strings and pre-compiled regular expressions).
See re2_regexp for available options.
See re2_syntax for regular expression syntax.


If FALSE, the default, return a list of string vectors. If TRUE, return a string matrix.


Number of string pieces to return. Default (Inf) returns all.


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.


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)

re2 documentation built on March 29, 2022, 5:05 p.m.