use fancy_regex::*; pub struct Template { pub tag: String, pub subtags: Vec, pub expression: Regex, } impl Template { pub fn from_str(pattern: &str, tag: String) -> Self { let pattern = format!("^(?:{pattern})"); let expression = Regex::new(&pattern).unwrap(); if let Some((head, tail)) = tag.split_once('(') { if let Some(tail) = tail.strip_suffix(')') { let tag = head.trim().to_string(); let subtags = tail.split(',').map(|t| t.trim().to_string()).collect(); return Self { tag, subtags, expression }; } } let subtags = Vec::new(); return Self { tag, subtags, expression }; } }