Struct fancy_regex::Expander

source ·
pub struct Expander { /* private fields */ }
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 regex contains 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.

Writes the expansion produced by expansion to dst. Potentially more efficient than calling expansion directly and writing the result.

Trait Implementations§

Formats the value using the given formatter. Read more

Returns the default expander used by Captures::expand.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.