commit
5eb377769e
@ -0,0 +1,3 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
*~
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "rematch"
|
||||
version = "0.1.0"
|
||||
authors = ["Avril <flanchan@cumallover.me>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
regex = "1"
|
@ -0,0 +1,22 @@
|
||||
extern crate regex;
|
||||
use regex::Regex;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
|
||||
if args.len() < 4 {
|
||||
println!("Usage: {} <str> <regex> <group>", args[0]);
|
||||
} else {
|
||||
let re = Regex::new(&args[2]).unwrap();
|
||||
let text = &args[1];
|
||||
let group: usize = args[3].parse().expect("Invalid group number.");
|
||||
|
||||
let groups = re.captures(&text).unwrap();
|
||||
|
||||
if group > groups.len() {
|
||||
eprintln!("Invalid group number.");
|
||||
} else {
|
||||
println!("{}", groups.get(group).unwrap().as_str());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue