January 2019
Intermediate to advanced
520 pages
14h 32m
English
Regular expressions contain a special language, used to write a pattern to extract data from a string. We need three patterns for our example:
There's a Regex::new function that creates regular expressions. Remove the previous USER_PATH constant and add three new regular expression constants in a lazy static block:
lazy_static! { static ref INDEX_PATH: Regex = Regex::new("^/(index\\.html?)?$").unwrap(); static ref USER_PATH: Regex = Regex::new("^/user/((?P<user_id>\\d+?)/?)?$").unwrap(); static ref USERS_PATH: Regex = Regex::new("^/users/?$").unwrap();}
As you can see, regular expressions look ...
Read now
Unlock full access