Created
September 7, 2019 18:17
-
-
Save kornysietsma/323b859949bacbf04ed03b8228fe2793 to your computer and use it in GitHub Desktop.
byte regex fail
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 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); | |
} | |
} |
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
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