Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created April 13, 2023 14:26
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 rust-play/92d4e4855015317451abad775adceec1 to your computer and use it in GitHub Desktop.
Save rust-play/92d4e4855015317451abad775adceec1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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