Ergonomic Rust bindings to the JavaScript standard built-in RegExp
object
In WASM environments that are attached to a JavaScript runtime, depending on a crate like regex
for regular expression matching can seem silly (at least when package size is a concern) - There's a perfectly fine
regular expression engine right there, in JavaScript! And while js-sys
does
expose the standard built-in RegExp
object, it does not aim to provide a convenient interface. \
This crate aims to bridge that gap.
See the rustdoc documentation for detailed usage information.
```rust use js_regexp::{RegExp, Flags}
let re = RegExp::new(
r#"(?
let result = re.exec("Hello, Alice!").unwrap(); let namedcaptures = result.captures.unwrap(); let namedcaptures = namedcaptures.getnamedcapturesmap();
asserteq!("Hello, Alice", result.matchslice); asserteq!(0, result.matchindex); asserteq!(12, result.matchlength); asserteq!("Hello", namedcaptures.get("greeting").unwrap().slice); asserteq!(7, namedcaptures.get("name").unwrap().index); ```