I need to filter strings that follow the rules below
- Must not contain any of
ab
,cd
,pq
, orxy
- Must contain a vowel
- Must contain at least one letter that appears at least twice in a row (like
mm
,zz
etc)
pub fn p1(lines: &str) -> u32 {
lines
.split_whitespace().filter(|line| { /* regex filter goes here */ })
.count() as u32
}
I'm not familiar with regex. I came up with the following regex rule but the regex crate doesn't seem to support look-around.
pub fn p1(args: &str) -> u32 {
let regexp = regex::RegexSet::new(&[
r"^((?!ab|cd|pq|xy).)*",
r"((.)\1{9,}).*",
r"(\b[aeiyou]+\b).*",
])
.unwrap();
let mut count = 0u32;
regexp
.matches(args)
.into_iter()
.collect::<Vec<_>>()
.iter()
.for_each(|c| {
println!("{:?}", c);
count += 1;
});
count
}