cat_re | R Documentation |
The function cat_re()
prints a regular expression to the console.
By default, the regular expression is not printed as an R string,
but as a ‘plain regular expression’. More specifically, the regular expression
is printed without surrounding quotation marks, and characters that are
special characters in R strings (such as quotation marks and backslashes)
are not escaped with a backslash. Also, by default, multi-line regular expressions are
printed as single-line regular expressions with all regular expression comments removed.
cat_re(x, format = c("plain", "R"), as_single_line = TRUE)
x |
An object of class |
format |
Character vector describing the requested format (as a |
as_single_line |
Logical. Whether |
WARNING: In the current implementation, the way the character #
is handled is
not guaranteed to be correct. More specifically, the code is not guaranteed
to correctly distinguish between a #
symbol that introduces a regular
expression comment and a #
symbol that doesn't do so. Firstly,
there is no testing whether at the point of encountering #
we're in
free-spacing mode. Second, there is no thorough testing whether or not
the #
symbol is part of a character class.
However, #
is processed correctly as long as any 'literal #' is
immediately preceded by either a backslash or an opening square bracket,
and any ‘comment-introducing #’ is not immediately preceded by
a backslash or an opening square bracket.
Invisibly, x
.
scan_re()
# single-line regular expression x <- "(?xi) \\b \\w* willing \\w* \\b" cat_re(x) y <- "(?xi) \\b # word boundary \\w* # optional prefix willing # stem \\w* # optional suffix \\b # word boundary" cat_re(y) cat_re(y, as_single_line = FALSE) cat_re(y, format = "R") cat_re(y, format = "R", as_single_line = FALSE) regex <- re("(?xi) \\b # word boundary \\w* # optional prefix willing # stem \\w* # optional suffix \\b # word boundary") cat_re(regex) cat_re(regex, as_single_line = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.