Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Created March 26, 2021 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crutchcorn/004066b2225c7f1093c7e249cabfcdf5 to your computer and use it in GitHub Desktop.
Save crutchcorn/004066b2225c7f1093c7e249cabfcdf5 to your computer and use it in GitHub Desktop.
Demo Rust tool to test importing
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