Skip to main content

RegexSet

Struct RegexSet 

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

RegexSet API for matching multiple patterns against the same input.

Implementations§

Source§

impl RegexSet

Source

pub fn new<I, S>(patterns: I) -> Result<Self>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Create a new RegexSet from an iterator of patterns using default options.

All patterns will use the same default configuration:

  • Case sensitive
  • Multi-line mode disabled
  • Dot does not match newline
  • Unicode mode enabled
§Errors

Returns an error if any pattern fails to compile.

Source

pub fn new_with_options<I, S>( patterns: I, options_builder: &RegexOptionsBuilder, ) -> Result<Self>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Create a new RegexSet from an iterator of patterns using specified options.

§Errors

Returns an error if any pattern fails to compile.

Source

pub fn from_regexes<I>(regexes: I, config: RegexSetOptions) -> Result<Self>
where I: IntoIterator<Item = Arc<Regex>>,

Create a new RegexSet from pre-built Arc<Regex> instances.

§Examples
use fancy_regex::{Regex, RegexBuilder, RegexInput, RegexSet, RegexSetOptions};
use std::sync::Arc;

// Create regexes with different options
let re1 = Arc::new(RegexBuilder::new(r"hello")
    .case_insensitive(true)
    .build()?);
let re2 = Arc::new(Regex::new(r"\d+")?);
let re3 = Arc::new(Regex::new(r"(?<=\w)end")?); // lookbehind - fancy pattern

// Combine them into a RegexSet
let set = RegexSet::from_regexes([re1, re2, re3], Default::default())?;

let text = "HELLO";
let mut matches = set
    .find_input(RegexInput::new(text))?
    .expect("expected at least one match");

let m = matches.next().expect("expected first match")?;
assert_eq!(m.pattern(), 0);
assert_eq!(m.as_str(), "HELLO");
assert!(matches.next().is_none());
§Errors

Returns an error if the multi-pattern DFA construction fails.

Source

pub fn len(&self) -> usize

Returns the number of patterns in the set.

Source

pub fn is_empty(&self) -> bool

Returns true if the set contains no patterns.

Source

pub fn find_input<'r, 't, S: Input + ?Sized>( &'r self, input: RegexInput<'t, S>, ) -> Result<Option<RegexSetMatchesAt<'r, 't, S>>>

Returns an iterator over matches at the earliest match position - if any. Iterator yields matches in pattern index order

Trait Implementations§

Source§

impl Clone for RegexSet

Source§

fn clone(&self) -> RegexSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RegexSet

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.