• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use lazy_static::lazy_static;
2 use regex::Regex;
3 
4 lazy_static! {
5     static ref USERNAME: Regex = {
6         println!("Compiling username regex...");
7         Regex::new("^[a-z0-9_-]{3,16}$").unwrap()
8     };
9 }
10 
main()11 fn main() {
12     println!("Let's validate some usernames.");
13     validate("fergie");
14     validate("will.i.am");
15 }
16 
validate(name: &str)17 fn validate(name: &str) {
18     // The USERNAME regex is compiled lazily the first time its value is accessed.
19     println!("is_match({:?}): {}", name, USERNAME.is_match(name));
20 }
21