#![allow(dead_code)]
use regex::Regex;
pub fn words(s: String, re: Option<Regex>) -> Vec<String> {
match re {
Some(rgx) => {
return rgx
.find_iter(&s)
.filter_map(|w| w.as_str().parse().ok())
.collect();
},
None => {
let mut result = Vec::new();
let mut word = String::new();
for (_index, char) in s.chars().enumerate() {
if char.is_alphanumeric() {
word.push(char);
} else {
if word.len() > 0 {
result.push(word);
word = String::new();
}
}
}
if word.len() > 0 {
result.push(word);
}
return result;
}
}
}