Regexp::new exception error
Closed this issue · 0 comments
What version of regex are you using?
If it isn't the latest version, then please upgrade and check whether the bug
is still present.
1.11.1
Describe the bug at a high level.
Give a brief description of the actual problem you're observing.
I'm getting regular expressions from the nmap fingerprint library, but when I use them individually, the regular expressions work, but when I create them through a loop, I get the error: Backreferences are not supported.
What are the steps to reproduce the behavior?
This section should almost always provide a COMPLETE Rust program that others
can compile and run with Cargo. It should be as small as possible.
If providing a small and simple reproduction is not easy, please explain why
and the maintainers will help you figure out next steps.
https://github.com/nmap/nmap/blob/master/nmap-service-probes nmap-service-probes.txt
use regex::Regex;
#[cfg(test)]
mod test{
use super::*;
#[test]
fn test_t_reg(){
compile();
}
}
fn compile(){
let mut file = OpenOptions::new().append(true).create(true).open("res.txt").unwrap();
let date:String = "\u{5}\0\r\u{3}\u{10}\0\0\0\u{18}\0\0\0\0\u{8}\u{1}@\u{4}\0\u{1}\u{5}\0\0\0\0".parse().unwrap();
let mut matten:Vec<String> =Vec::new();
let nsp_str = include_str!("../nmap-service-probes.txt");
let mut nsp_lines = Vec::new();
for l in nsp_str.lines() {
nsp_lines.push(l.to_string());
}
for line in nsp_lines {
if line.contains("#") {
continue;
} else if line.contains("Exclude") {
continue;
}
if line.starts_with("match"){
let line_split: Vec<&str> = line.split(" ").collect();
let line_other = line_split[2..].to_vec().join(" ");
let line_other_replace = line_other.replace("|s", "|");
let line_other_split: Vec<&str> = line_other_replace.split("|").collect();
let pattern = line_other_split[1].to_string();
// println!("{}", pattern);
matten.push(pattern);
}
}
let mut true_patten:Vec<String> = Vec::new();
// let set = RegexSet::new(matten.clone()).unwrap();
// let matches: Vec<_> = set.matches(&date).into_iter().collect();
for ma in matten.clone() {
match Regex::new(&ma) {
Ok(re) => {
true_patten.push(ma)
},
Err(e) => {
if ma.contains("0....") {
println!("Regex Error: {:?}", e);
println!("Regex Error: {}", ma);
}
// println!("Regex Error: {}", ma);
continue
}
}
}
let test = Regex::new("^\x05\0\r\x03\x10\0\0\0\x18\0\0\0....\x04\0\x01\x05\0...$").unwrap();
let res = test.captures(&date);
println!("{:?}", res);
}
What is the actual behavior?
If you provide a Rust program in the previous section, then this should be the
output of that program.
What is the expected behavior?
What do you expect the output to be?