Created
March 26, 2021 19:00
-
-
Save crutchcorn/004066b2225c7f1093c7e249cabfcdf5 to your computer and use it in GitHub Desktop.
Demo Rust tool to test importing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use regex::Regex; | |
fn main() { | |
let phone_regex = Regex::new(r"\d{3}-(\d{3})-(\d{4})").unwrap(); | |
let phone_matches = phone_regex.captures("555-555-5555"); | |
return match phone_matches | |
.map(|caps| { | |
( | |
caps.get(1).map(|m| m.as_str()), | |
caps.get(2).map(|m| m.as_str()), | |
) | |
}) | |
.and_then(|(first_opt, second_opt)| match (first_opt, second_opt) { | |
(Some(first), Some(second)) => Some((first, second)), | |
_ => None, | |
}) { | |
Some((first, second)) => { | |
println!("{}/{}", first, second); | |
} | |
_ => {} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment