Skip to main content

FuzzyRegexBuilder

Struct FuzzyRegexBuilder 

Source
pub struct FuzzyRegexBuilder { /* private fields */ }
Expand description

Builder for constructing a FuzzyRegex with custom configuration.

Implementations§

Source§

impl FuzzyRegexBuilder

Source

pub fn new(pattern: &str) -> Self

Create a new builder with the given pattern.

Source

pub fn case_insensitive(self, yes: bool) -> Self

Set case-insensitive matching.

Source

pub fn verbose(self, yes: bool) -> Self

Enable verbose mode (ignore whitespace and allow # comments).

In verbose mode:

  • Whitespace is ignored (use \s or [ ] for literal space)
  • # starts a comment that extends to end of line

This allows formatting patterns for readability:

(?x)
[A-Z][a-z]+     # First name
\s+             # Whitespace
[A-Z][a-z]+     # Last name
Source

pub fn dot_all(self, yes: bool) -> Self

Enable dot-all mode (. matches newlines).

By default, . matches any character except newlines. When enabled, . matches any character including \n.

Source

pub fn multi_line(self, yes: bool) -> Self

Enable multi-line mode (^ and $ match at line boundaries).

By default, ^ matches only at the start of text and $ only at the end. When enabled:

  • ^ also matches after each newline
  • $ also matches before each newline
Source

pub fn ungreedy(self, yes: bool) -> Self

Enable ungreedy mode (invert default greediness of quantifiers).

When enabled:

  • *, +, ? become non-greedy (match as little as possible)
  • *?, +?, ?? become greedy (match as much as possible)

This is equivalent to the (?U) inline flag.

Source

pub fn global(self, yes: bool) -> Self

Enable global mode (find all matches).

When enabled, use find_iter() to get all matches. When disabled (default), stops at first valid match (faster). This is equivalent to the (?g) inline flag.

Source

pub fn greedy_first(self, yes: bool) -> Self

Enable greedy first-match mode (similar to mrab-regex behavior).

When enabled, searches position by position and returns the first match found. This is faster than the default best-match behavior when matches exist early in the text, but may not find the optimal match.

Default behavior (greedy_first=false): searches all positions to find best match. Greedy first (greedy_first=true): stops at first match found.

Source

pub fn unicode(self, yes: bool) -> Self

Enable Unicode mode for character classes.

When enabled:

  • \w matches Unicode word characters (not just ASCII [a-zA-Z0-9_])
  • \d matches Unicode digits
  • \s matches Unicode whitespace

This is equivalent to the (?u) inline flag.

Source

pub fn similarity(self, threshold: f32) -> Self

Set the similarity threshold (0.0 - 1.0).

Matches with similarity below this threshold are rejected.

Source

pub fn edits(self, count: u8) -> Self

Set the default number of edits allowed for fuzzy matching.

This applies to literals without explicit fuzziness markers.

Source

pub fn fuzzy(self, limits: FuzzyLimits) -> Self

Set detailed fuzzy limits for default matching.

Source

pub fn penalties(self, penalties: FuzzyPenalties) -> Self

Set edit operation penalties.

Source

pub fn max_threads(self, max: usize) -> Self

Set the maximum number of threads for NFA simulation.

Higher values allow more complex patterns but use more memory.

Source

pub fn partial(self, yes: bool) -> Self

Enable partial matching.

When enabled, matches that reach the end of the text are considered successful even if they haven’t completed. The Match::partial() method can be used to check if a match is partial.

This is useful for streaming input or when the text may be truncated.

Source

pub fn timeout(self, duration: Duration) -> Self

Set a timeout for matching operations.

If a match operation takes longer than the timeout, it will be cancelled. The default is no timeout.

Note: Timeout is checked at certain checkpoints during matching, so it’s not precise. The actual time may exceed the timeout slightly.

Source

pub fn build(self) -> Result<FuzzyRegex>

Build the FuzzyRegex.

§Errors

Returns an error if the pattern is invalid or cannot be compiled.

Trait Implementations§

Source§

impl Clone for FuzzyRegexBuilder

Source§

fn clone(&self) -> FuzzyRegexBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FuzzyRegexBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.