How to replace multiple consecutive question marks (?) with a single question mark in Rust

1 Answer

0 votes
fn main() {
    let input = "What??? Why?? How?????";

    // Create a regex pattern to match one or more consecutive question marks
    let re = regex::Regex::new(r"\?+").unwrap();

    // Replace all matches with a single '?'
    let result = re.replace_all(input, "?");

    println!("{}", result);
}



    
/*
run:

What? Why? How?
   
*/

 



answered Jul 24, 2025 by avibootz
...