pub fn try_search<C: Cursor>(
regex: &Regex,
cache: &mut Cache,
input: &mut Input<C>,
) -> Result<Option<Match>, MatchError>
Expand description
Returns the start and end offset of the leftmost match. If no match
exists, then None
is returned.
This is like Regex::find
but with two differences:
- It is not generic over
Into<Input>
and instead accepts a&Input
. This permits reusing the sameInput
for multiple searches without needing to create a new one. This may help with latency. - It returns an error if the search could not complete where as
Regex::find
will panic.
§Errors
This routine errors 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 returns an error, callers cannot know whether a match exists or not.