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_owned_pattern
for an alternative that takes ownership of a String
pattern instead.
Sourcepub fn new_with_owned_pattern(
pattern: String,
flags: Flags,
) -> Result<Self, JsValue>
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.
Sourcepub fn new_with_copied_names(
pattern: &str,
flags: Flags,
) -> Result<Self, JsValue>
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.
Sourcepub fn exec<'h, 'a>(
&'a mut self,
haystack: &'h str,
) -> Option<ExecResult<'h, 'a>>
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.
Sourcepub fn stream<'s, 'h>(
&'s mut self,
haystack: &'h str,
) -> RegExpStream<'s, 'h, 'p>
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