pub struct Pattern { /* private fields */ }Expand description
A user pattern compiled to the regular-expression substrate used by every matcher.
Patterns match a complete candidate. Use ** in a glob or .* in a regular expression when a
prefix or suffix is intentionally unconstrained.
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn glob(glob: impl AsRef<str>) -> Result<Self, PatternError>
pub fn glob(glob: impl AsRef<str>) -> Result<Self, PatternError>
Compiles a portable, case-sensitive glob.
The supported wildcards are *, **, ?, character classes such as [abc] and [a-z],
and negated character classes such as [!0-9]. Backslashes are path separators rather than
escapes so one glob behaves the same on every host OS.
Sourcepub fn glob_with(
glob: impl AsRef<str>,
options: PatternOptions,
) -> Result<Self, PatternError>
pub fn glob_with( glob: impl AsRef<str>, options: PatternOptions, ) -> Result<Self, PatternError>
Compiles a glob with explicit options.
Sourcepub fn regex(expression: impl AsRef<str>) -> Result<Self, PatternError>
pub fn regex(expression: impl AsRef<str>) -> Result<Self, PatternError>
Compiles a regular expression with complete-candidate matching.
Sourcepub fn regex_with(
expression: impl AsRef<str>,
options: PatternOptions,
) -> Result<Self, PatternError>
pub fn regex_with( expression: impl AsRef<str>, options: PatternOptions, ) -> Result<Self, PatternError>
Compiles a regular expression with explicit options.
Sourcepub fn literal(literal: impl AsRef<str>) -> Result<Self, PatternError>
pub fn literal(literal: impl AsRef<str>) -> Result<Self, PatternError>
Compiles a complete literal string, including characters meaningful to globs and regexes.
Sourcepub fn literal_with(
literal: impl AsRef<str>,
options: PatternOptions,
) -> Result<Self, PatternError>
pub fn literal_with( literal: impl AsRef<str>, options: PatternOptions, ) -> Result<Self, PatternError>
Compiles a complete literal string with explicit options.
Sourcepub const fn syntax(&self) -> PatternSyntax
pub const fn syntax(&self) -> PatternSyntax
Returns whether this pattern originated as a glob or a regular expression.
Sourcepub fn matches(&self, candidate: &str) -> bool
pub fn matches(&self, candidate: &str) -> bool
Returns whether the complete normalized candidate matches.
Sourcepub fn replace(&self, candidate: &str, replacement: &str) -> String
pub fn replace(&self, candidate: &str, replacement: &str) -> String
Replaces this pattern’s match in a normalized candidate.
Rust regex replacement syntax is supported, including $1 and ${name} captures. Because
every Pattern is anchored, a matching replacement always covers the complete candidate.