Struct Regex

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

POSIX regular expression.

Implementations§

Source§

impl Regex

Source

pub fn new(pattern: &str, flags: CompFlags) -> Result<Regex, String>

Compiles pattern as a regular expression.

By default, pattern is assumed to be a basic regular expression. To interpret it as an extended regular expression, add CompFlags::EXTENDED to the flags. See also other CompFlags values to control some other aspects of the regex.

§Returns

Compiled regex or an error message.

Source

pub fn matches( &self, input: &str, max_matches: usize, flags: MatchFlags, ) -> Result<Vec<Match>, String>

Matches input string against regex, looking for up to max_matches matches.

Regexes can contain parenthesized subexpressions. This method will return up to max_matches-1 of those. First match is reserved for the text that the whole regex matched.

flags dictate how matching is performed. See MatchFlags for details.

§Returns
  • Ok with an empty vector if no match found, or if max_matches is 0 and there were no errors.
  • Ok with a non-empty vector if max_matches was non-zero and a match was found. First element of the vector is the text that regex as a whole matched. The rest of the elements are pieces of text that were matched by parenthesized subexpressions.
  • Err with an error message.

Trait Implementations§

Source§

impl Drop for Regex

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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