April 2026
Intermediate
631 pages
16h 20m
English
This section provides the code solutions for the practice exercises in Section 17.5. The code is largely self-explanatory; however, we have included comments and additional explanations wherever necessary to enhance understanding.
Matching telephone numbers without using \d shorthand
use regex::Regex;fn main() { let re = Regex::new(r"^\d......").unwrap(); let text = "My phone number is 816030 and the second phone number is 816694"; for cap in re.captures_iter(text) { println!("match: {:?}", &cap[0]); }}
Understanding the question mark quantifier
fn main() { let re = Regex::new(r"_?\w+\.rs").unwrap(); let text = "file.rs _file.rs test.rs _test.rs"; for cap in re.find_iter(text) { println!("{}", cap.as_str()); }}
Using ...
Read now
Unlock full access