-
-
Save rust-play/92d4e4855015317451abad775adceec1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
use bytes::Bytes; | |
use regex::bytes::Regex as BytesRegex; | |
fn main() { | |
let val = b"2020-01-01"; | |
let my_regex = BytesRegex::new(r"\d{4}-(\d{2})-\d{2}").unwrap(); | |
let month = my_regex.captures(val).unwrap().get(1).unwrap(); | |
let month_digit = std::str::from_utf8(month.as_bytes()).unwrap().parse::<u8>().unwrap(); | |
println!("month smaller than 12: {}", month_digit<=12); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment