Created
November 15, 2016 12:31
-
-
Save willmurphyscode/59e5800026b60b8d18cca5508469b034 to your computer and use it in GitHub Desktop.
A regex to tell you whether a string is a "scientific name". (Note: very scientific)
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
extern crate regex; | |
use regex::Regex; | |
/* | |
1. At least 1 "cool" adjective ("horrendous", "incredible", "monstrous", "ultimate") | |
2. A science-sounding intermediate noun ("space", "time", "matter", "energy") | |
3. An onomatopoeia that makes a cool sound ("boom", "kablooie", "swoosh") | |
*/ | |
pub fn is_scientific_name(input: &str) -> bool { | |
let re = Regex::new(r"(horrendous|monstrous|incredible|ultimate)+\s(space|time|matter|energy)\s(boom|kablooie|swoosh)").unwrap(); | |
re.is_match(input) | |
} | |
#[test] | |
fn horrendous_space_kablooie() { | |
let test_string = "horrendous space kablooie"; | |
assert!(is_scientific_name(&test_string)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment