Function human_regex::capture
source · pub fn capture(target: HumanRegex) -> HumanRegex
Expand description
Add a numbered capturing group around an expression
use human_regex::{capture, digit, exactly, text};
let regex_string = capture(exactly(4, digit()))
+ text("-")
+ capture(exactly(2, digit()))
+ text("-")
+ capture(exactly(2, digit()));
let caps = regex_string.to_regex().captures("2010-03-14").unwrap();
assert_eq!("2010", caps.get(1).unwrap().as_str());
assert_eq!("03", caps.get(2).unwrap().as_str());
assert_eq!("14", caps.get(3).unwrap().as_str());