pub fn find_iter<'r, 'c, C: Cursor>(
regex: &'r Regex,
cache: &'c mut Cache,
input: Input<C>,
) -> FindMatches<'r, 'c, C> ⓘ
Expand description
Returns an iterator over all non-overlapping leftmost matches in the given bytes. If no match exists, then the iterator yields no elements.
§Panics
This routine panics if the search could not complete. This can occur in a number of circumstances:
- The configuration of the lazy DFA may permit it to “quit” the search. For example, setting quit bytes or enabling heuristic support for Unicode word boundaries. The default configuration does not enable any option that could result in the lazy DFA quitting.
- The configuration of the lazy DFA may also permit it to “give up” on a search if it makes ineffective use of its transition table cache. The default configuration does not enable this by default, although it is typically a good idea to.
- When the provided
Input
configuration is not supported. For example, by providing an unsupported anchor mode.
When a search panics, callers cannot know whether a match exists or not.
The above conditions also apply to the iterator returned as well. For example, if the lazy DFA gives up or quits during a search using this method, then a panic will occur during iteration.
Use Regex::try_search
with util::iter::Searcher
if you want to handle these error conditions.
§Example
use regex_automata::{hybrid::regex::Regex, Match};
let re = Regex::new("foo[0-9]+")?;
let mut cache = re.create_cache();
let text = "foo1 foo12 foo123";
let matches: Vec<Match> = re.find_iter(&mut cache, text).collect();
assert_eq!(matches, vec![
Match::must(0, 0..4),
Match::must(0, 5..10),
Match::must(0, 11..17),
]);