Skip to main content

Regex

Struct Regex 

Source
pub struct Regex { /* private fields */ }
Expand description

compiled regex backed by a lazy DFA.

uses a Mutex for mutable DFA state.

Implementations§

Source§

impl Regex

Source

pub fn new(pattern: &str) -> Result<Regex, Error>

compile a pattern with default options.

let re = resharp::Regex::new(r"\b\w+\b").unwrap();
Source

pub fn with_options(pattern: &str, opts: EngineOptions) -> Result<Regex, Error>

compile a pattern with custom EngineOptions.

use resharp::{Regex, EngineOptions};

let re = Regex::with_options(
    r"hello",
    EngineOptions::default().case_insensitive(true),
).unwrap();
assert!(re.is_match(b"HELLO").unwrap());
Source

pub fn from_node( b: RegexBuilder, node: NodeId, opts: EngineOptions, ) -> Result<Regex, Error>

build from a pre-constructed AST node.

Source

pub fn is_hardened(&self) -> bool

whether hardened linear-scan mode is enabled

Source

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

pub fn find_anchored(&self, input: &[u8]) -> Result<Option<Match>, Error>

longest match anchored at position 0.

returns None if the pattern does not match at position 0.

Source

pub fn is_match(&self, input: &[u8]) -> Result<bool, Error>

whether the pattern matches anywhere in the input.

faster than find_all when you only need a yes/no answer.

Auto Trait Implementations§

§

impl !Freeze for Regex

§

impl RefUnwindSafe for Regex

§

impl Send for Regex

§

impl Sync for Regex

§

impl Unpin for Regex

§

impl UnsafeUnpin for Regex

§

impl UnwindSafe for Regex

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.