Expand description
Ergonomic Rust bindings to the JavaScript standard built-in RegExp
object
Basic usage
use js_regexp::{flags, RegExp};
let mut re = RegExp::new(r#"(?<greeting>\w+), (?<name>\w+)"#, flags!("d")).unwrap();
let result = re.exec("Hello, Alice!").unwrap();
let mut iter = result.captures().unwrap().iter();
let named_captures = result.named_captures().unwrap();
assert_eq!("Hello, Alice", result.match_slice);
assert_eq!(0, result.match_index);
assert_eq!(12, result.match_length);
assert_eq!("Hello", iter.next().unwrap().slice);
assert_eq!("Hello", named_captures.get("greeting").unwrap().slice);
assert_eq!(5, iter.next().unwrap().length);
assert_eq!(7, named_captures.get("name").unwrap().index);
Macros
- Checks validity of a flags string literal at compile time and inserts a therefore safe runtime call to
Flags::new_unchecked
.
Structs
- An index, length, slice, and optional group name of a capture in a haystack.
- The result of a successful
RegExp::exec
call. - Boolean fields representing regular expression flags.
- A checked interface for setting regular expression flags.
- A wrapped JavaScript
RegExp
. The main type of this crate. - Repeatedly match in the same haystack using the same regular expression.