use std::fs::File; use std::io::prelude::*; use std::path::Path; use regex::Regex; fn main() { // Create a path to the desired file let path = Path::new("nyger.txt"); let display = path.display(); // Open the path in read-only mode, returns `io::Result` let mut file = match File::open(&path) { Err(why) => panic!("couldn't open {}: {}", display, why), Ok(file) => file, }; // Read the file contents into a string, returns `io::Result` let mut s = String::new(); let re = Regex::new(r"\d").unwrap(); //file.read_to_string(&mut s); //match file.read_to_string(&mut s) { // Err(why) => panic!("couldn't read {}: {}", display, why), // Ok(_) => match re.captures(&s) { // Some(caps) => println!("{}", caps.get(0).unwrap().as_str()), // None => println!("chuj ci w dupe") // } //} file.read_to_string(&mut s); match file.read_to_string(&mut s) { Err(why) => panic!("couldn't read {}: {}", display, why), Ok(_) => for number in re.find_iter(&s) { print!("{}", number.as_str()); } } }