Struct js_regexp::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_ownership for an alternative that takes ownership of a String pattern instead.

source

pub fn new_with_ownership( 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_copying(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>(&'p self, haystack: &'h str) -> Option<ExecResult<'h, 'p>>

Calls the underlying JavaScript RegExp’s exec method.
Returns None if the JavaScript call returns null. The returned ExecResult’s captures member is None if the underlying JavaScript call returns an object that does not have an indices property, which is only present when the d flag is set for the expression.

MDN documentation

source

pub fn inspect_flags(&self) -> &FlagSets

Returns a read-only reference to the flags set for this regular expression.

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> 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.