Struct RegExp

Source
pub struct RegExp<'p> { /* private fields */ }
Expand description

A wrapped JavaScript RegExp. The main type of this crate.

MDN documentation

Implementations§

Source§

impl<'p> RegExp<'p>

Source

pub fn new(pattern: &'p str, flags: Flags) -> Result<Self, JsValue>

Constructs a new regular expression, backed by a RegExp in JavaScript.
Returns an error if JavaScript throws a SyntaxError exception.
When constructed by this function, the returned value’s lifetime becomes tied to the provided &str pattern. See new_with_owned_pattern for an alternative that takes ownership of a String pattern instead.

Source

pub fn new_with_owned_pattern( pattern: String, flags: Flags, ) -> Result<Self, JsValue>

Constructs a new regular expression, backed by a RegExp in JavaScript.
Returns an error if JavaScript throws a SyntaxError exception.
Takes ownership of the provided String pattern. Use new instead if you have a &'static str, or if it otherwise makes sense for the constructed value to store only a reference to your pattern.

Source

pub fn new_with_copied_names( pattern: &str, flags: Flags, ) -> Result<Self, JsValue>

Constructs a new regular expression, backed by a RegExp in JavaScript.
Returns an error if JavaScript throws a SyntaxError exception.
Unlike with new, the returned structure does not hold on to a reference to the provided &str pattern. This is achieved by copying any group names from the JavaScript heap every time the regular expression is used.

Source

pub fn exec<'h, 'a>( &'a mut self, haystack: &'h str, ) -> Option<ExecResult<'h, 'a>>

Calls the underlying JavaScript RegExp’s exec method.
Returns None if the JavaScript call returns null.

MDN documentation

Source

pub fn flags(&self) -> &FlagSets

The flags set for this regular expression.

Source

pub fn stream<'s, 'h>( &'s mut self, haystack: &'h str, ) -> RegExpStream<'s, 'h, 'p>

Creates a RegExpStream for repeatedly matching in the same haystack

Source

pub fn inner(&mut self) -> &mut RegExp

The inner js_sys::RegExp. Useful for directly accessing the lastIndex property (MDN) and the test method (MDN), which are not worth wrapping explicitly as they don’t require fancy conversions.

Trait Implementations§

Source§

impl<'p> Debug for RegExp<'p>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'p> Freeze for RegExp<'p>

§

impl<'p> RefUnwindSafe for RegExp<'p>

§

impl<'p> !Send for RegExp<'p>

§

impl<'p> !Sync for RegExp<'p>

§

impl<'p> Unpin for RegExp<'p>

§

impl<'p> UnwindSafe for RegExp<'p>

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.