// 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"(?m)(ip|ec2)-((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)-){3}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))($|(?:ec2|[^.]+\.compute)\.internal\.$)?").unwrap();
let string = "us-west-2.elasticmapreduce.amazonaws.com
ip-10-27-87-173
ip-10-27-91-145.us-west-2.compute.internal
ip-10-27-90-170.us-west-2.compute.internal.us-west-2.compute.internal
ec2-54-82-117-121
ec2-54-82-117-121.compute-1.amazonaws.com
ec2-54-82-117-121.compute-1.amazonaws.com.us-west-2.compute.internal
ip-10-27-102-175.us-west-2.compute.internal.us-west-2.compute.internal
ip-10-27-180-213.us-west-2.compute.internal
ip-10-27-107-136.us-west-2.compute.internal.us-west-2.compute.internal
ip-10-27-209-104.us-east-1.compute.internal
ip-10-27-209-104.us-east-1.compute.internal.us-east-1.compute.internal
ip-10-27-209-104.us-east-1.compute.internal.ec2.internal
ip-10-27-112-164.ec2.internal
ip-255-27-112-164.ec2.internal";
// 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/