pub struct RegExp<'p> { /* private fields */ }
Expand description
A wrapped JavaScript RegExp
. The main type of this crate.
Implementations§
source§impl<'p> RegExp<'p>
impl<'p> RegExp<'p>
sourcepub fn new(pattern: &'p str, flags: Flags) -> Result<Self, JsValue>
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.
sourcepub fn new_with_ownership(
pattern: String,
flags: Flags
) -> Result<Self, JsValue>
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.
sourcepub fn new_with_copying(pattern: &str, flags: Flags) -> Result<Self, JsValue>
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.
sourcepub fn exec<'h>(&'p self, haystack: &'h str) -> Option<ExecResult<'h, 'p>>
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.
sourcepub fn inspect_flags(&self) -> &FlagSets
pub fn inspect_flags(&self) -> &FlagSets
Returns a read-only reference to the flags set for this regular expression.