Description Usage Arguments Details Value See Also Examples
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.
1 2 3 |
x |
a character vector containing a regular expression. If the length of
|
format |
a character vector describing the requested output format. If the
length of |
as_single_line |
a boolean vector specifying whether the regular expression should be
converted to a single-line regular expression (which also implies
removing all regular expression comments) prior to printing.
If the length of |
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 bracked, and any ‘comment-introducing #’ is not immediately preceded by a backslash or an opening square bracket.
The (invisible) value of cat_re
is the same as its first argument, viz.
the character vector x
.
See also scan_re
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # single-line regular expression
x <- "(?xi) \\b \\w* willing \\w* \\b"
cat_re(x)
# multi-line regular expression
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.