Struct regress::Regex

source ·
pub struct Regex { /* private fields */ }
Expand description

A Regex is the compiled version of a pattern.

Implementations§

source§

impl Regex

source

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

Construct a regex by parsing pattern using the default flags. An Error may be returned if the syntax is invalid. Note that this is rather expensive; prefer to cache a Regex which is intended to be used more than once.

source

pub fn with_flags<F>(pattern: &str, flags: F) -> Result<Regex, Error>
where F: Into<Flags>,

Construct a regex by parsing pattern with flags. An Error may be returned if the syntax is invalid. Note it is preferable to cache a Regex which is intended to be used more than once, as the parse may be expensive. For example:

source

pub fn from_unicode<I, F>(pattern: I, flags: F) -> Result<Regex, Error>
where I: Iterator<Item = u32> + Clone, F: Into<Flags>,

Construct a regex by parsing pattern with flags, where pattern is an iterator of u32 Unicode codepoints. An Error may be returned if the syntax is invalid. This allows parsing regular expressions from exotic strings in other encodings, such as UTF-16 or UTF-32.

source

pub fn find(&self, text: &str) -> Option<Match>

Searches text to find the first match.

source

pub fn find_iter<'r, 't>(&'r self, text: &'t str) -> Matches<'r, 't>

Searches text, returning an iterator over non-overlapping matches. Note that the resulting Iterator borrows both the regex 'r and the input string as 't.

source

pub fn find_from<'r, 't>( &'r self, text: &'t str, start: usize ) -> Matches<'r, 't>

Returns an iterator for matches found in ‘text’ starting at byte index start. Note this may be different from passing a sliced text in the case of lookbehind assertions. Example:

 use regress::Regex;
 let text = "xyxy";
 let re = Regex::new(r"(?<=x)y").unwrap();
 let t1 = re.find(&text[1..]).unwrap().range();
 assert!(t1 == (2..3));
 let t2 = re.find_from(text, 1).next().unwrap().range();
 assert!(t2 == (1..2));
source

pub fn find_ascii(&self, text: &str) -> Option<Match>

Searches text to find the first match. The input text is expected to be ascii-only: only ASCII case-folding is supported.

source

pub fn find_iter_ascii<'r, 't>(&'r self, text: &'t str) -> AsciiMatches<'r, 't>

Searches text, returning an iterator over non-overlapping matches. The input text is expected to be ascii-only: only ASCII case-folding is supported.

source

pub fn find_from_ascii<'r, 't>( &'r self, text: &'t str, start: usize ) -> AsciiMatches<'r, 't>

Returns an iterator for matches found in ‘text’ starting at byte index start.

Trait Implementations§

source§

impl Clone for Regex

source§

fn clone(&self) -> Regex

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Regex

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for Regex

source§

fn from_str(s: &str) -> Result<Self, Error>

Attempts to parse a string into a regular expression

§

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations§

§

impl Freeze for Regex

§

impl RefUnwindSafe for Regex

§

impl Send for Regex

§

impl Sync for Regex

§

impl Unpin 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.