(Regex help) How to filter strings using regex

I need to filter strings that follow the rules below

  1. Must not contain any of ab , cd , pq , or xy
  2. Must contain a vowel
  3. 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
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.