Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Created November 15, 2016 12:31
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 willmurphyscode/59e5800026b60b8d18cca5508469b034 to your computer and use it in GitHub Desktop.
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)
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