js-regexp

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.

Usage

See the rustdoc documentation for detailed usage information.

Basic example

```rust use js_regexp::{RegExp, Flags}

let re = RegExp::new( r#"(?\w+), (?\w+)"#, Flags::new("d").unwrap(), ) .unwrap();

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); ```