regex-map

Crates.ioregex-map
lib.rsregex-map
version0.1.0
sourcesrc
created_at2023-10-04 09:12:27.841114
updated_at2023-10-04 09:12:27.841114
descriptionAssociative container where the keys are regular expressions.
homepagehttps://github.com/Palmik/regex-map-rs
repositoryhttps://github.com/Palmik/regex-map-rs
max_upload_size
id992008
size7,435
Petr Pilaƙ (Palmik)

documentation

README

Associative container where the keys are regular expressions, based on the regex::RegexSet data structure.

Example use:

use regex_map::RegexMap;

let map = RegexMap::new([
   ("foo", 1),
   ("bar", 2),
   ("foobar", 3),
   ("^foo$", 4),
   ("^bar$", 5),
   ("^foobar$", 6),
]);

assert_eq!(map.get("foo").cloned().collect::<Vec<_>>(), vec![1, 4]);
assert_eq!(map.get("bar").cloned().collect::<Vec<_>>(), vec![2, 5], );
assert_eq!(map.get("foobar").cloned().collect::<Vec<_>>(), vec![1, 2, 3, 6]);
assert_eq!(map.get("XXX foo XXX").cloned().collect::<Vec<_>>(), vec![1]);
assert_eq!(map.get("XXX bar XXX").cloned().collect::<Vec<_>>(), vec![2]);

for value in map.get("foo") {
    println!("Foo match: {}", value);
}

TODOs:

  • Consider adding get_with_match, which would return iterator over the values and the matches for the individual regexes.
Commit count: 1

cargo fmt