Struct fancy_regex::Expander [−][src]
pub struct Expander { /* fields omitted */ }Expand description
A set of options for expanding a template string using the contents of capture groups.
Implementations
Returns an expander that uses Python-compatible syntax.
Expands all instances of \num or \g<name> in replacement
to the corresponding capture group num or name, and writes
them to the dst buffer given.
name may be an integer corresponding to the index of the
capture group (counted by order of opening parenthesis where \0 is the
entire match) or it can be a name (consisting of letters, digits or
underscores) corresponding to a named capture group.
num must be an integer corresponding to the index of the
capture group.
If num or name isn’t a valid capture group (whether the name doesn’t exist
or isn’t a valid index), then it is replaced with the empty string.
The longest possible number is used. e.g., \10 looks up capture
group 10 and not capture group 1 followed by a literal 0.
To write a literal \, use \\.
Checks template for errors. The following conditions are checked for:
- A reference to a numbered group that does not exist in
regex - A reference to a numbered group (other than 0) when
regexcontains named groups - A reference to a named group that does not occur in
regex - An opening group name delimiter without a closing delimiter
- Using an empty string as a group name
Escapes the substitution character in text so it appears literally
in the output of expansion.
assert_eq!( fancy_regex::Expander::default().escape("Has a literal $ sign."), "Has a literal $$ sign.", );
Expands the template string template using the syntax defined
by this expander and the values of capture groups from captures.
Appends the expansion produced by expansion to dst. Potentially more efficient
than calling expansion directly and appending to an existing string.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Expanderimpl UnwindSafe for Expander