pub struct Regex { /* private fields */ }Expand description
A compiled regex. Clones share the native pattern and may match concurrently.
Implementations§
Source§impl Regex
impl Regex
Sourcepub fn captures_len(&self) -> usize
pub fn captures_len(&self) -> usize
Returns the number of capture groups, including group zero.
Sourcepub fn is_match(&self, subject: &[u8]) -> bool
pub fn is_match(&self, subject: &[u8]) -> bool
Returns whether the regex matches anywhere in the input.
Sourcepub fn is_match_at(&self, subject: &[u8], start: usize) -> bool
pub fn is_match_at(&self, subject: &[u8], start: usize) -> bool
Searches from a byte offset while preserving anchor and lookbehind context.
An offset beyond the input returns false.
Sourcepub fn is_full_match(&self, subject: &[u8]) -> bool
pub fn is_full_match(&self, subject: &[u8]) -> bool
Returns whether the regex matches the entire input.
Sourcepub fn find<'s>(&self, subject: &'s [u8]) -> Option<Match<'s>>
pub fn find<'s>(&self, subject: &'s [u8]) -> Option<Match<'s>>
Finds the first match in the input.
Sourcepub fn find_at<'s>(&self, subject: &'s [u8], start: usize) -> Option<Match<'s>>
pub fn find_at<'s>(&self, subject: &'s [u8], start: usize) -> Option<Match<'s>>
Finds the first match at or after a byte offset, preserving input context.
An offset beyond the input returns None.
Sourcepub fn captures<'s>(&self, subject: &'s [u8]) -> Option<Captures<'s>>
pub fn captures<'s>(&self, subject: &'s [u8]) -> Option<Captures<'s>>
Returns the capture groups of the first match.
Sourcepub fn captures_at<'s>(
&self,
subject: &'s [u8],
start: usize,
) -> Option<Captures<'s>>
pub fn captures_at<'s>( &self, subject: &'s [u8], start: usize, ) -> Option<Captures<'s>>
Returns captures for the first match at or after a byte offset.
Input context is preserved; offsets beyond the input return None.
Sourcepub fn scan<'s, F, B>(&self, subject: &'s [u8], callback: F) -> ControlFlow<B>
pub fn scan<'s, F, B>(&self, subject: &'s [u8], callback: F) -> ControlFlow<B>
Visits non-overlapping matches in leftmost-first order.
Return ControlFlow::Continue(()) to continue or ControlFlow::Break(value)
to stop and return that value. Empty matches are included: after one,
nonempty alternatives at the same position are tried before advancing.
Callbacks may perform nested scans. Callback panics propagate after the
native scan has stopped, without unwinding through C++.
use std::ops::ControlFlow;
use javelin_pattern::bytes::Regex;
let re = Regex::new(r"\d+")?;
let mut ranges = Vec::new();
let result = re.scan(b"12 and 34", |m| {
ranges.push(m.range());
ControlFlow::<()>::Continue(())
});
assert_eq!(result, ControlFlow::Continue(()));
assert_eq!(ranges, [0..2, 7..9]);Sourcepub fn scan_at<'s, F, B>(
&self,
subject: &'s [u8],
start: usize,
callback: F,
) -> ControlFlow<B>
pub fn scan_at<'s, F, B>( &self, subject: &'s [u8], start: usize, callback: F, ) -> ControlFlow<B>
Like Regex::scan, starting at a byte offset into the original input.
An offset beyond the input completes without invoking the callback.
Sourcepub fn scan_captures<'s, F, B>(
&self,
subject: &'s [u8],
callback: F,
) -> ControlFlow<B>
pub fn scan_captures<'s, F, B>( &self, subject: &'s [u8], callback: F, ) -> ControlFlow<B>
Visits capture groups with the iteration and stopping rules of Regex::scan.
Capture ranges are copied into Rust-owned storage for each match.
Sourcepub fn scan_captures_at<'s, F, B>(
&self,
subject: &'s [u8],
start: usize,
callback: F,
) -> ControlFlow<B>
pub fn scan_captures_at<'s, F, B>( &self, subject: &'s [u8], start: usize, callback: F, ) -> ControlFlow<B>
Like Regex::scan_captures, starting at a byte offset into the original input.
An offset beyond the input completes without invoking the callback.