BinRegex

Struct BinRegex 

Source
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: usize

Implementations§

Source§

impl BinRegex

Source

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.

Source

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);
Source

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.

Source

pub fn match_length<'a, T>(&'a self, input: &'a T) -> Option<BitIndex>

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.