How to match any single character in a string using regular expression with Rust

1 Answer

0 votes
use regex::Regex;

fn main() {
    let pattern = Regex::new(r"b.d").unwrap();

    let test_strings = vec![
        "bud",  // returns true (1)
        "bid",  // returns true (1)
        "bed",  // returns true (1)
        "b d",  // returns true (1)
        "bat",  // returns false (0)
        "bd",   // returns false (0)
        "bead", // returns false (0)
    ];

    for test_str in test_strings {
        let match_found = pattern.is_match(test_str);
        println!("{}", match_found);
    }
}


     
/*
run:
  
true
true
true
true
false
false
false
    
*/

 



answered Feb 15, 2025 by avibootz
...