How to remove all digits from a string using regex in Rust

1 Answer

0 votes
use regex::Regex;

fn main() {
    let mut s = String::from("abs322kl59po@$d0057qn8");

    // Create a regular expression to match digits
    let digits_regex = Regex::new(r"[0-9]").unwrap();

    // Use regex::replace_all to replace digit characters with an empty string
    s = digits_regex.replace_all(&s, "").to_string();

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



   
/*
run:
  
absklpo@$dqn
  
*/

 



answered Dec 10, 2024 by avibootz
...