Skip to content

Instantly share code, notes, and snippets.

@kornysietsma
Created September 7, 2019 18:17
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 kornysietsma/323b859949bacbf04ed03b8228fe2793 to your computer and use it in GitHub Desktop.
Save kornysietsma/323b859949bacbf04ed03b8228fe2793 to your computer and use it in GitHub Desktop.
byte regex fail
use regex::bytes::Regex;
fn main() {
let re = Regex::new(r"^(.*)$").unwrap();
let line: Vec<u8> = vec![
46, 45, 191, 87, 110, 176, 108, 158, 46, 45, 191, 87, 110, 176, 108, 158,
];
let s = std::str::from_utf8(&line);
if s.is_err() {
println!("Error in converting from utf8:{:?}", s);
}
let rcaps = re.captures(&line);
if rcaps.is_none() {
println!("Bad regex parsing: '{:?}'", line);
} else {
let caps = rcaps.unwrap();
println!("caps: {:?}", caps);
}
}
Error in converting from utf8:Err(Utf8Error { valid_up_to: 2, error_len: Some(1) })
Bad regex parsing: '[46, 45, 191, 87, 110, 176, 108, 158, 46, 45, 191, 87, 110, 176, 108, 158]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment