// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?xm)^((?!
PA(?:
\*(?:N\s*\d+\s*\.\s*\d+\s*\*ADP)?
| \#\s*N\s*\d+\s*
(?:\.\s*\d+\s*
(?:,\s*\d+\s*\.\s*\d+\s*)?
)?
\#ADP\s*\d
| \#\s*N\s*\d+\s*
(?:,\s*\d+\s*
(?:\.\s*\d+\s*,\s*\d+\s*)?
)?
\#ADP\s*\d
| \#\s*N(?:\s*\d+\s*,\s*)?
\s*\d+\s*
(?:\.\s*\d+\s*)?
(?:
[\.,]\s*\d+\s*,\s*\d+\s*
| -\s*\d+\s*
(?:\.\s*\d+\s*)?
)
\#ADP\s*\d
| \#\s*N\s*\d+\s*
\.\s*\d+\s*
-\s*\d+\s*
\.\s*\d+\s*
,\s*\d+\s*
\.\s*\d+\s*
\#ADP\s*\#PUSH
| \#NUAL,AZ,AN\#FOP\d
)
).)*$").unwrap();
let string = "# OP's samples
PA#N1.1#ADP1
PA#N1.1,1.2#ADP1,2
PA#N1#ADP4
PA#N1,2#ADP4
PA#N1,2.1,3#ADP1
PA#N1.1-3#ADP1
PA#N1,1-3#ADP1
PA#N1.1- 3.2#ADP1,2
PA#NUAL,AZ,AN#FOP123
PA#N1.1-2.1,3.1#ADP#PUSH
PA*N1.1*ADP
PA*
# The same with some spaces adde here and there
PA# N 1.1 #ADP1
PA#N 1.1,1.2#ADP1,2
PA#N1#ADP4
PA#N1,2 #ADP4
PA#N1,2. 1,3#ADP1
PA#N1.1-3#ADP1
PA#N1.1- 3.2#ADP1,2
PA#NUAL,AZ,AN#FOP123
PA#N1.1-2 . 1 , 3 . 1 #ADP#PUSH
PA*N1 .1*ADP
PA#N1.1...#5#SOME TEXT
";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/