js-regexp
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! 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 docs.rs for detailed usage information.
Basic example
use
let re = new
.unwrap;
let result = re.exec.unwrap;
let named_captures = result.captures.unwrap;
let named_captures = named_captures.get_named_captures_map;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Stability and future
js-regexp is not tested extensively, and I am not quite happy with the API yet.
I will keep making changes as I use it in my own projects and get a better feel for where there are issues,
and where this crate could still be nicer to use. The public interface may change between minor versions while
js-regexp is 0.x.x, but because of its simplicity and small scope I expect any required changes in consuming code to
be quick and easy.
An easy and useful addition would be a wrapper around
RegExp.test(),
so I'll probably add that at some point.
Issues and pull requests are welcome!
License
Starting with version 0.1.1, js-regexp is MIT-licensed. 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 away. Turns out copyright, as a system, isn't very good at creating justice. So just, like, don't be evil. Please!