struct IGNORE_RE {
    __private_field: (),
}

Fields§

§__private_field: ()

Methods from Deref<Target = RegexSet>§

source

pub fn is_match(&self, haystack: &str) -> bool

Returns true if and only if one of the regexes in this set matches the haystack given.

This method should be preferred if you only need to test whether any of the regexes in the set should match, but don’t care about which regexes matched. This is because the underlying matching engine will quit immediately after seeing the first match instead of continuing to find all matches.

Note that as with searches using Regex, the expression is unanchored by default. That is, if the regex does not start with ^ or \A, or end with $ or \z, then it is permitted to match anywhere in the haystack.

Example

Tests whether a set matches somewhere in a haystack:

use regex::RegexSet;

let set = RegexSet::new([r"\w+", r"\d+"]).unwrap();
assert!(set.is_match("foo"));
assert!(!set.is_match("☃"));
source

pub fn is_match_at(&self, haystack: &str, start: usize) -> bool

Returns true if and only if one of the regexes in this set matches the haystack given, with the search starting at the offset given.

The significance of the starting point is that it takes the surrounding context into consideration. For example, the \A anchor can only match when start == 0.

Panics

This panics when start >= haystack.len() + 1.

Example

This example shows the significance of start. Namely, consider a haystack foobar and a desire to execute a search starting at offset 3. You could search a substring explicitly, but then the look-around assertions won’t work correctly. Instead, you can use this method to specify the start position of a search.

use regex::RegexSet;

let set = RegexSet::new([r"\bbar\b", r"(?m)^bar$"]).unwrap();
let hay = "foobar";
// We get a match here, but it's probably not intended.
assert!(set.is_match(&hay[3..]));
// No match because the  assertions take the context into account.
assert!(!set.is_match_at(hay, 3));
source

pub fn matches(&self, haystack: &str) -> SetMatches

Returns the set of regexes that match in the given haystack.

The set returned contains the index of each regex that matches in the given haystack. The index is in correspondence with the order of regular expressions given to RegexSet’s constructor.

The set can also be used to iterate over the matched indices. The order of iteration is always ascending with respect to the matching indices.

Note that as with searches using Regex, the expression is unanchored by default. That is, if the regex does not start with ^ or \A, or end with $ or \z, then it is permitted to match anywhere in the haystack.

Example

Tests which regular expressions match the given haystack:

use regex::RegexSet;

let set = RegexSet::new([
    r"\w+",
    r"\d+",
    r"\pL+",
    r"foo",
    r"bar",
    r"barfoo",
    r"foobar",
]).unwrap();
let matches: Vec<_> = set.matches("foobar").into_iter().collect();
assert_eq!(matches, vec![0, 2, 3, 4, 6]);

// You can also test whether a particular regex matched:
let matches = set.matches("foobar");
assert!(!matches.matched(5));
assert!(matches.matched(6));
source

pub fn matches_at(&self, haystack: &str, start: usize) -> SetMatches

Returns the set of regexes that match in the given haystack.

The set returned contains the index of each regex that matches in the given haystack. The index is in correspondence with the order of regular expressions given to RegexSet’s constructor.

The set can also be used to iterate over the matched indices. The order of iteration is always ascending with respect to the matching indices.

The significance of the starting point is that it takes the surrounding context into consideration. For example, the \A anchor can only match when start == 0.

Panics

This panics when start >= haystack.len() + 1.

Example

Tests which regular expressions match the given haystack:

use regex::RegexSet;

let set = RegexSet::new([r"\bbar\b", r"(?m)^bar$"]).unwrap();
let hay = "foobar";
// We get matches here, but it's probably not intended.
let matches: Vec<_> = set.matches(&hay[3..]).into_iter().collect();
assert_eq!(matches, vec![0, 1]);
// No matches because the  assertions take the context into account.
let matches: Vec<_> = set.matches_at(hay, 3).into_iter().collect();
assert_eq!(matches, vec![]);
source

pub fn len(&self) -> usize

Returns the total number of regexes in this set.

Example
use regex::RegexSet;

assert_eq!(0, RegexSet::empty().len());
assert_eq!(1, RegexSet::new([r"[0-9]"]).unwrap().len());
assert_eq!(2, RegexSet::new([r"[0-9]", r"[a-z]"]).unwrap().len());
source

pub fn is_empty(&self) -> bool

Returns true if this set contains no regexes.

Example
use regex::RegexSet;

assert!(RegexSet::empty().is_empty());
assert!(!RegexSet::new([r"[0-9]"]).unwrap().is_empty());
source

pub fn patterns(&self) -> &[String]

Returns the regex patterns that this regex set was constructed from.

This function can be used to determine the pattern for a match. The slice returned has exactly as many patterns givens to this regex set, and the order of the slice is the same as the order of the patterns provided to the set.

Example
use regex::RegexSet;

let set = RegexSet::new(&[
    r"\w+",
    r"\d+",
    r"\pL+",
    r"foo",
    r"bar",
    r"barfoo",
    r"foobar",
]).unwrap();
let matches: Vec<_> = set
    .matches("foobar")
    .into_iter()
    .map(|index| &set.patterns()[index])
    .collect();
assert_eq!(matches, vec![r"\w+", r"\pL+", r"foo", r"bar", r"foobar"]);

Trait Implementations§

source§

impl Deref for IGNORE_RE

§

type Target = RegexSet

The resulting type after dereferencing.
source§

fn deref(&self) -> &RegexSet

Dereferences the value.
source§

impl LazyStatic for IGNORE_RE

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> 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> IntoResult<T> for T

§

type Err = Infallible

source§

fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V