re_split {re} | R Documentation |
Split a string by a regular expression pattern
Description
re_split
splits each element of a character vector into substrings based on a specified pattern
(regular expression). If the provided pattern is not already a compiled pattern object, it compiles it using
re_compile
. The function allows for controlling the maximum number of splits performed.
Usage
re_split(pattern, string, ..., maxsplit = -1L)
Arguments
pattern |
A regular expression pattern or a compiled pattern object. |
string |
A character vector where each element is a string to be split. |
... |
Arguments passed on to
|
maxsplit |
The maximum number of splits to perform on each string. If -1L (default), all possible splits are performed. |
Value
A list of character vectors, where each vector contains the substrings resulting from splitting the
corresponding element of string
.
See Also
Python re.split() documentation
Examples
pattern <- re_compile("\\s+")
re_split(pattern, "Split this string") # Splits on whitespace
re_split("\\W+", "Split,with!punctuation.morestuff", maxsplit = 2)