pub struct Regex { /* private fields */ }Expand description
Lazily compiled regex instance. Uses Mutex for interior mutability.
Implementations§
Source§impl Regex
impl Regex
Source§impl Regex
impl Regex
Sourcepub const SEEK_INITIAL: u32 = 0
pub const SEEK_INITIAL: u32 = 0
Initial state for Regex::seek_fwd / Regex::seek_rev cursors.
Sourcepub fn stream_chunk<F: FnMut(usize)>(
&self,
chunk: &[u8],
state: StreamState,
on_match: F,
) -> Result<StreamState, Error>
pub fn stream_chunk<F: FnMut(usize)>( &self, chunk: &[u8], state: StreamState, on_match: F, ) -> Result<StreamState, Error>
Feed one chunk, resuming from state. Emits shortest match ends in absolute offsets.
Pass StreamState::new() for the first chunk.
Sourcepub fn seek_fwd(
&self,
input: &[u8],
state: u32,
pos: usize,
) -> Result<Option<(u32, usize)>, Error>
pub fn seek_fwd( &self, input: &[u8], state: u32, pos: usize, ) -> Result<Option<(u32, usize)>, Error>
Forward cursor scan; returns the next shortest match end as (resume_state, end).
First call: state = SEEK_INITIAL, pos = 0. Subsequent calls: pass back the returned values.
Sourcepub fn seek_rev(
&self,
input: &[u8],
state: u32,
pos: usize,
) -> Result<Option<(u32, usize)>, Error>
pub fn seek_rev( &self, input: &[u8], state: u32, pos: usize, ) -> Result<Option<(u32, usize)>, Error>
Reverse cursor scan over input[..pos] using rev LDFA on _*·rev(node).
Returns the next shortest match start (rightmost-first) as (resume_state, start).
First call: state = SEEK_INITIAL, pos = input.len().
Source§impl Regex
impl Regex
Sourcepub fn new(pattern: &str) -> Result<Regex, Error>
pub fn new(pattern: &str) -> Result<Regex, Error>
compile a pattern with default options.
let re = resharp::Regex::new(r"\b\w+\b").unwrap();Sourcepub fn with_options(pattern: &str, opts: RegexOptions) -> Result<Regex, Error>
pub fn with_options(pattern: &str, opts: RegexOptions) -> Result<Regex, Error>
compile a pattern with custom RegexOptions.
use resharp::{Regex, RegexOptions};
let re = Regex::with_options(
r"hello",
RegexOptions::default().case_insensitive(true),
).unwrap();
assert!(re.is_match(b"HELLO").unwrap());Sourcepub fn find_all(&self, input: &[u8]) -> Result<Vec<Match>, Error>
pub fn find_all(&self, input: &[u8]) -> Result<Vec<Match>, Error>
all non-overlapping leftmost-first matches as [start, end) byte ranges.
let re = resharp::Regex::new(r"\d+").unwrap();
let m = re.find_all(b"abc 123 def 456").unwrap();
assert_eq!(m.len(), 2);
assert_eq!((m[0].start, m[0].end), (4, 7));