Ergonomic Rust bindings to the JavaScript standard built-in RegExp
object
In Wasm environments that are glued 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! This crate aims to provide a convenient interface using js-sys
's
raw bindings to JavaScript's RegExp
built-in.
See docs.rs for detailed usage information.
```rust use js_regexp::{flags, Flags, RegExp};
let mut re = RegExp::new(r#"(?
let mut iter = result.captures().unwrap().iter(); let namedcaptures = result.namedcaptures().unwrap();
asserteq!("Hello, Alice", result.matchslice); asserteq!(0, result.matchindex); asserteq!(12, result.matchlength); asserteq!("Hello", iter.next().unwrap().slice); asserteq!("Hello", namedcaptures.get("greeting").unwrap().slice); asserteq!(5, iter.next().unwrap().length); asserteq!(7, namedcaptures.get("name").unwrap().index); ```
js-regexp is not tested extensively. \ The public interface may change across minor versions while js-regexp is pre-1.0.0, but because of its simplicity and small scope I expect any required changes in consuming code to be quick and easy.
Issues and pull requests are welcome!
js-regexp is somewhat arbitrarily released under the MIT License. Worrying about copyright with small utility crates like this seems not worth it - more restrictive licenses can never address all possible cases in just the right way anyway. Copyright's ability to create justice is limited. So just don't be evil, please ❤️