pub struct BinRegex {
pub n_groups: usize,
/* private fields */
}Expand description
A compiled variation of regular expressions intended for searching binary data. A
BinRegex can be used to search binary data for patterns
Fields§
§n_groups: usizeImplementations§
Source§impl BinRegex
impl BinRegex
Sourcepub fn new(pattern: &str) -> Result<BinRegex, String>
pub fn new(pattern: &str) -> Result<BinRegex, String>
Compiles a binary regular expression. Once compiled, this object can be used repeatedly to search input buffers.
Sourcepub fn find<'a, T>(&self, input: &'a T) -> Option<BinMatch<'a, T>>
pub fn find<'a, T>(&self, input: &'a T) -> Option<BinMatch<'a, T>>
Searches for the first match in the input given, and if found returns a BinMatch
object corresponding to the match. If no match is found, returns None.
§Examples
use bitutils2::{BinRegex, BitIndex};
let input = vec![0x00, 0x0a, 0xbc, 0x00, 0x00, 0x00, 0xff, 0x00];
let re1 = BinRegex::new("ABC_{8,}''").unwrap();
let m1 = re1.find(&input).unwrap();
assert_eq!(m1.span(), (BitIndex::new(1, 4), BitIndex::new(6, 2)));
let re2 = BinRegex::new("ABC_{8,}'_").unwrap();
assert_eq!(re2.find(&input), None);Sourcepub fn find_iter<'a, T>(&'a self, input: &'a T) -> BinMatches<'a, T> ⓘ
pub fn find_iter<'a, T>(&'a self, input: &'a T) -> BinMatches<'a, T> ⓘ
Returns an iterator that yields successive non-overlapping matches in the input buffer.
pub fn match_length<'a, T>(&'a self, input: &'a T) -> Option<BitIndex>where
&'a T: BitIndexable,
Sourcepub fn captures<'a, T>(&'a self, input: &'a T) -> Option<BinCaptures<'_, T>>
pub fn captures<'a, T>(&'a self, input: &'a T) -> Option<BinCaptures<'_, T>>
This routine searches for the first match of this regex in the input given, and if found,
returns not only the overall match but also the matches of each capture group in the
expression. If no match is found, then None is returned.
Auto Trait Implementations§
impl Freeze for BinRegex
impl RefUnwindSafe for BinRegex
impl !Send for BinRegex
impl !Sync for BinRegex
impl Unpin for BinRegex
impl UnwindSafe for BinRegex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more