| parse_regex_pattern {stringmagic} | R Documentation |
stringmagic's regular expression parser
Description
Parse regular expression with custom flags and obtain the final pattern to be parsed as well as the vector of flags
Usage
parse_regex_pattern(
pattern,
authorized_flags,
parse_flags = TRUE,
parse_logical = TRUE,
envir = parent.frame()
)
Arguments
pattern |
Character scalar, the regular expression pattern to parse. |
authorized_flags |
Character vector representing the flags to be parsed. Use the empty string if no flags are allowed. |
parse_flags |
Logical scalar, default is |
parse_logical |
Logical scalar, default is |
envir |
An environment, default is |
Details
This is an internal tool that is exposed in order to facilitate checking what's going on.
There is no error handling.
Value
This function always returns a list of 4 elements:
-
flags: the character vector of flags. If no flags were found, this is the empty string. -
patterns: the vector of regex patterns. -
is_or: logical vector of the same length aspatterns. Indicates for each pattern if it should be attached to the previous patterns with a logical OR (FALSEmeans a logicalAND). -
is_not: logical vector of the same length aspatterns. Indicates for each pattern if it should be negated.
Author(s)
Laurent Berge
See Also
String operations: string_is(), string_get(), string_clean(), string_split2df().
Chain basic operations with string_ops(). Clean character vectors efficiently
with string_clean().
Use string_vec() to create simple string vectors.
String interpolation combined with operation chaining: string_magic(). You can change string_magic
default values with string_magic_alias() and add custom operations with string_magic_register_fun().
Display messages while benefiting from string_magic interpolation with cat_magic() and message_magic().
Other tools with aliases:
cat_magic_alias(),
string_magic(),
string_magic_alias(),
string_ops_alias(),
string_vec_alias()
Examples
parse_regex_pattern("f/hello", c("fixed", "ignore"))
x = "john"
parse_regex_pattern("fm/{x} | Doe", c("fixed", "ignore", "magic"))