pub struct Pattern { /* private fields */ }Expand description
A compiled regular expression — the payload of Value::Pattern.
Every regex operation in the runtime goes through this type, so swapping engines is confined to this file.
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn captures<'h>(&self, haystack: &'h str) -> Option<Captures<'h>>
pub fn captures<'h>(&self, haystack: &'h str) -> Option<Captures<'h>>
Leftmost match anywhere in haystack.
Sourcepub fn captures_full<'h>(&self, haystack: &'h str) -> Option<Captures<'h>>
pub fn captures_full<'h>(&self, haystack: &'h str) -> Option<Captures<'h>>
Match the whole of haystack, or nothing — Java’s Matcher.matches(),
which Clojure’s re-matches delegates to.
Anchored inside the pattern rather than by checking the span of an
unanchored match, because the two differ wherever the engine’s
leftmost-first preference picks a shorter alternative: a|ab prefers
a, and .*?x? prefers the empty match, neither of which reaches the
end of the haystack even though a full match exists. With \A/\z in
the automaton the engine only ever offers a whole-haystack match.
Sourcepub fn captures_at<'h>(
&self,
haystack: &'h str,
start: usize,
) -> Option<Captures<'h>>
pub fn captures_at<'h>( &self, haystack: &'h str, start: usize, ) -> Option<Captures<'h>>
Leftmost match at or after byte offset start. Look-around still sees
the text before start, which is what makes this the right primitive
for stepping a Matcher forward.
Sourcepub fn replace<'h>(&self, haystack: &'h str, replacement: &str) -> Cow<'h, str>
pub fn replace<'h>(&self, haystack: &'h str, replacement: &str) -> Cow<'h, str>
Replace the leftmost match in haystack; $1-style references in
replacement expand to capture groups.
Sourcepub fn replace_all<'h>(
&self,
haystack: &'h str,
replacement: &str,
) -> Cow<'h, str>
pub fn replace_all<'h>( &self, haystack: &'h str, replacement: &str, ) -> Cow<'h, str>
Replace every non-overlapping match in haystack.