// 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)^config d(hcp|ns) ip(v4)? (<[^>]*>|(?:\d+\.){3}\d+)( port| timeout|\s*$)( <[^>]*>\s*$| \d+\s*$|\s*$)|config (router|interface) (id|bgp|name) (<[^>]*>\s*$|<[^>]*> id <[^>]*>\s*$|\d+\s*$|[a-z]+ id \d+\s*$|\s*$)").unwrap();
let string = "config dhcp ip <dhcp-ipaddress> port <dhcp-port-number>
config dhcp ip <dhcp-ipaddress> timeout <time-out-value>
config dhcp ipv4 <dhcp-ipaddress>
config dns ip <dns-ipaddress> port <dns-port-number>
config dns ip <dns-ipaddress> timeout <time-out-value>
config router bgp <bgp-number>
config interface id <interface-id>
config interface name <interface-name> id <interface-id>
config dhcp ip 1.1.1.1 port 8080
config dhcp ip 1.1.1.2 timeout 120
config dhcp ip 1.1.1.1 timeout 120
config dhcp ip 1.1.1.2 port 8080
config dhcp ipv4 1.1.1.3
config interface id 12
config interface name abc id 12
config interface id 13
config interface name xyz id 13
config dhcp ip 1.1.1.1 port 8080
config dhcp ip 1.1.1.1 timeout 120
config dhcp ip 1.1.1.2 timeout 120
config dhcp ip 1.1.1.2 port 8080
config dhcp ipv4 1.1.1.3
config interface id 12
config interface name abc id 12
config interface id 13
config interface name xyz id 13";
// 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/