pub struct RegexSet { /* private fields */ }Expand description
RegexSet API for matching multiple patterns against the same input.
Implementations§
Source§impl RegexSet
impl RegexSet
Sourcepub fn new<I, S>(patterns: I) -> Result<Self>
pub fn new<I, S>(patterns: I) -> Result<Self>
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.
Sourcepub fn new_with_options<I, S>(
patterns: I,
options_builder: &RegexOptionsBuilder,
) -> Result<Self>
pub fn new_with_options<I, S>( patterns: I, options_builder: &RegexOptionsBuilder, ) -> Result<Self>
Create a new RegexSet from an iterator of patterns using specified options.
§Errors
Returns an error if any pattern fails to compile.
Sourcepub fn from_regexes<I>(regexes: I, config: RegexSetOptions) -> Result<Self>
pub fn from_regexes<I>(regexes: I, config: RegexSetOptions) -> Result<Self>
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.
Sourcepub fn find_input<'r, 't, S: Input + ?Sized>(
&'r self,
input: RegexInput<'t, S>,
) -> Result<Option<RegexSetMatchesAt<'r, 't, S>>>
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§
Auto Trait Implementations§
impl Freeze for RegexSet
impl RefUnwindSafe for RegexSet
impl Send for RegexSet
impl Sync for RegexSet
impl Unpin for RegexSet
impl UnsafeUnpin for RegexSet
impl UnwindSafe for RegexSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more