Expand description
Ergonomic Rust bindings to the JavaScript standard built-in RegExp
object
Basic usage
use js_regexp::{RegExp, Flags}
let re = RegExp::new(
r#"(?<greeting>\w+), (?<name>\w+)"#,
Flags::new("d").unwrap(),
)
.unwrap();
let result = re.exec("Hello, Alice!").unwrap();
let named_captures = result.captures.unwrap();
let named_captures = named_captures.get_named_captures_map();
assert_eq!("Hello, Alice", result.match_slice);
assert_eq!(0, result.match_index);
assert_eq!(12, result.match_length);
assert_eq!("Hello", named_captures.get("greeting").unwrap().slice);
assert_eq!(7, named_captures.get("name").unwrap().index);
Structs
- An index, length, slice, and optional group name of a capture in a haystack.
- A list of
Capture
s. - The result of a successful
RegExp::exec
call. - Boolean fields representing regular expression flags.
- Restrictive interface for setting regular expression flags.
- A wrapped JavaScript
RegExp
. The main type of this crate.
Enums
- A name of a named capture group, backed either by a slice of a pattern or an owned
String
copied from JavaScript.