[−][src]Struct rure::RegexSet
Methods from Deref<Target = RegexSet>
pub fn is_match(&self, text: &[u8]) -> bool
[src]
Returns true if and only if one of the regexes in this set matches the text 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
text.
Example
Tests whether a set matches some text:
let set = RegexSet::new(&[r"\w+", r"\d+"]).unwrap(); assert!(set.is_match("foo")); assert!(!set.is_match("☃"));
pub fn matches(&self, text: &[u8]) -> SetMatches
[src]
Returns the set of regular expressions that match in the given text.
The set returned contains the index of each regular expression that
matches in the given text. 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.
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
text.
Example
Tests which regular expressions match the given text:
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));
pub fn len(&self) -> usize
[src]
Returns the total number of regular expressions in this set.
pub fn patterns(&self) -> &[String]
[src]
Returns the patterns that this set will match on.
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
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(|match_idx| &set.patterns()[match_idx]) .collect(); assert_eq!(matches, vec![r"\w+", r"\pL+", r"foo", r"bar", r"foobar"]);
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,