build_format_regex | R Documentation |
Allow glue
-style formatting using keyworded regular expressions. The
original glue
string (anything that isn't expanded by glue
) is treated as
a string literal, whereas the contents of populated values can be regular
expressions, allowing for a more user-friendly way to construct complicated
regular expressions.
build_format_regex(
format,
format_re,
...,
type = re_backticked(),
description = re_any()
)
re_backticked()
re_any()
escape_non_glue_re(x)
format |
( |
format_re |
( |
... |
Additional arguments provide keyworded capture groups for |
type |
( |
description |
( |
x |
( |
To bypass glue entirely and use a standard regular expression, use
format_re
.
The provided regular expression must match all characters from the start of a
string to the end. The string also matches using "dot all" syntax, meaning
that the .
expression will also match newline characters.
(character[1]:
) A regular expression string, built from component sub-expressions.
re_backticked()
: Match within backticks
re_any()
: Match any
escape_non_glue_re()
: Escape all regular expression special characters
In addition, avoid escaping {}
's that appear to be used as glue
keywords.
Handles only simple cases, and does not handle recusive curly nesting.
re <- roxytypes:::build_format_regex(
"{as}{any}{bs}",
as = "a+",
bs = "b+",
any = ".*?"
)
roxytypes:::regex_capture(re, "aaaa\n\nbb", perl = TRUE)
text <- "@param (`test(\")\")`)"
pattern <- sprintf("`%s`", re_backticked())
m <- regexec(pattern, text, perl = TRUE)
regmatches(text, m)[[1]]
# [1] "`test(\")\")`"
# curlies escaped, as this does not appear to be a glue-style usage
roxytypes:::escape_non_glue_re(".{1,3}")
# curlies not escaped, as this is a glue-style usage
roxytypes:::escape_non_glue_re("this is a {test}")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.