View source: R/parsers_string.R
by_split | R Documentation |
Splits a string by using a split pattern and then applies the parser p
to the resulting character vector. If finish = TRUE
then the parser should
completely consume its input, otherwise the parser fails. If
finish = FALSE
then any remaining part of the string is discarded.
by_split(p, split, finish = TRUE, fixed = FALSE, perl = FALSE)
p |
A parser. |
split |
a string (or object which can be coerced to such) containing regular expression(s) (unless fixed = TRUE) to use for splitting. If empty matches occur, in particular if split has length 0, x is split into single characters. |
finish |
logical. Should the parser completely consume the string?
Defaults to |
fixed |
logical. If |
perl |
logical. Should Perl-compatible regexps be used? |
The function base::strsplit()
is used to perform the splitting. The
parameters split
, fixed
and perl
are passed on to that function.
A parser.
base::strsplit()
, by_symbol()
by_split((literal("a") %then% literal("b")),"\\t") ("a\tb") # success
by_split((literal("a") %then% literal("b")),"\\t") ("a\tb\tc") # failure
by_split((literal("a") %then% literal("b")),"\\t", finish=FALSE) ("a\tb\tc") # success
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.