use std::collections::HashMap; use regex::Regex; lazy_static! { // https://regex101.com/r/V9zYQu/1/ pub static ref HUMAN_REGEX: Regex = Regex::new(r"(?xi) (?P (?P (?Pa|an|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen)| (?Pone|two|three|four|five|six|seven|eight|nine)| (?Pten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety)| (?P (?Pten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety) .(?Pone|two|three|four|five|six|seven|eight|nine) )| (?P\d+) ) (\s+)?h(ou)?(r)?s? )? (?P\s*(,|and)?\s+)? (?P (?P (?Pa|an|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen)| (?Pone|two|three|four|five|six|seven|eight|nine)| (?Pten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety)| (?P (?Pten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety) .(?Pone|two|three|four|five|six|seven|eight|nine) )| (?P\d+) ) (\s+)?m(in)?(ute?)?s? )? \s+ago ").unwrap(); pub static ref DATETIME_REGEX: Regex = Regex::new(r"(?xi) (?P\d{4}) # the year, mandatory . (?P\d{2}) # the month, mandatory . (?P\d{2}) # the day, mandatory (. # a separator (?P\d{2}) # the hour, optional (. # a separator (?P\d{2})? # the minute, optional (. # a separator (?P\d{2}))?)?)? # the second, optional, implies minute (?P (?PZ)|((?P\+|-)(?P\d{1,2}):(?P\d{2})) )? # the offset, optional ").unwrap(); pub static ref HOUR_REGEX: Regex = Regex::new(r"(?xi) (?P\d{1,2}) # the hour, mandatory (. # a separator (?P\d{2})? # the minute, optional (. # a separator (?P\d{2}))?)? # the second, optional, implies minute (?P (?PZ)|((?P\+|-)(?P\d{1,2}):(?P\d{2})) )? # the offset, optional ").unwrap(); pub static ref NUMBER_VALUES: HashMap<&'static str, i64> = { vec![ ("a", 1), ("an", 1), ("ten", 10), ("eleven", 11), ("twelve", 12), ("thirteen", 13), ("fourteen", 14), ("fifteen", 15), ("sixteen", 16), ("seventeen", 17), ("eighteen", 18), ("nineteen", 19), ("one", 1), ("two", 2), ("three", 3), ("four", 4), ("five", 5), ("six", 6), ("seven", 7), ("eight", 8), ("nine", 9), ("twenty", 20), ("thirty", 30), ("forty", 40), ("fifty", 50), ("sixty", 60), ("seventy", 70), ("eighty", 80), ("ninety", 90), ].into_iter().collect() }; }