regex_capture_lookup

Function regex_capture_lookup 

Source
pub fn regex_capture_lookup<S>(
    pattern: S,
    value: S,
    names: Vec<S>,
) -> HashMap<S, String>
where S: Into<String> + AsRef<str> + Clone + Eq + Hash,
Expand description

Helper function to create a lookup dictionary for regex captures

ยงExample

use acorn_lib::util::regex_capture_lookup;
let lookup = regex_capture_lookup(
    r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})",
    "2023-06-30",
    vec!["year", "month", "day"]
);
assert_eq!(lookup["year"], "2023");
assert_eq!(lookup["month"], "06");
assert_eq!(lookup["day"], "30");