|
|
@ -1,6 +1,10 @@
|
|
|
|
|
|
|
|
#[cfg(not(feature = "perl"))]
|
|
|
|
extern crate regex;
|
|
|
|
extern crate regex;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(feature = "perl"))]
|
|
|
|
use regex::Regex;
|
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(feature = "perl"))]
|
|
|
|
fn main() {
|
|
|
|
fn main() {
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
|
|
|
|
|
|
|
@ -11,12 +15,42 @@ fn main() {
|
|
|
|
let text = &args[1];
|
|
|
|
let text = &args[1];
|
|
|
|
let group: usize = args[3].parse().expect("Invalid group number.");
|
|
|
|
let group: usize = args[3].parse().expect("Invalid group number.");
|
|
|
|
|
|
|
|
|
|
|
|
let groups = re.captures(&text).unwrap();
|
|
|
|
match re.captures(&text) {
|
|
|
|
|
|
|
|
|
|
|
|
if group > groups.len() {
|
|
|
|
Some(groups) => {
|
|
|
|
eprintln!("Invalid group number.");
|
|
|
|
if group > groups.len() {
|
|
|
|
} else {
|
|
|
|
eprintln!("Invalid group number.");
|
|
|
|
println!("{}", groups.get(group).unwrap().as_str());
|
|
|
|
} else {
|
|
|
|
|
|
|
|
println!("{}", groups.get(group).unwrap().as_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
None => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "perl")]
|
|
|
|
|
|
|
|
extern crate pcre;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "perl")]
|
|
|
|
|
|
|
|
use pcre::Pcre;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "perl")]
|
|
|
|
|
|
|
|
fn main () {
|
|
|
|
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.len() < 4 {
|
|
|
|
|
|
|
|
println!("Usage: {} <str> <regex> <group>", args[0]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let mut re = Pcre::compile(&args[2]).expect("Invalid regex.");
|
|
|
|
|
|
|
|
let text = &args[1];
|
|
|
|
|
|
|
|
let group: usize = args[3].parse().expect("Invalid group number.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match re.exec(&text) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Some(m) if m.string_count() > group => println!("{}", m.group(group)),
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|