// 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)name\[(?<policy_name>[\w\.\-\d\s]+)\]uuid\[(?<uuid>[\w\d\.\-\s]+)\]srcintf\[(?<source_interface>[\w\.\-\s\d]+)\]dstintf\[(?<destination_interface>[\w\d\-\.\s]+)\]srcaddr\[(?<source_address>[\w\d\.\-\s]+)\]dstaddr\[(?<destination_address>[\w\d\.\-\s]+)\]action\[(?<policy_action>\w+)\]schedule\[(?<policy_schedule>[\w\d\s\.\-]+)\]service\[(?<policy_services>[\w\s\.\d\-]+)\](utm-status\[(?<utm_status>[\w\s\.\-\d]+)\])?logtraffic\[(?<log_traffic>[\d\w\s\.\-]+)\]ippool\[(?<pool_status>[\s\w\d\.\-]+)\]poolname\[(?<pool_name>[\w\s\d\.\-]+)\](profile-protocol-options\[(?<protocol_options>[\w\s\d\.\-]+)\]ssl-ssh-profile\[(?<ssl_ssh_profile>[\w\d\.\s\-]+)\]ips-sensor\[(?<ips_sensor>[\w\d\s\.\-]+)\])?nat\[(?<nat_status>[\w\d\s\.\-]+)\]").unwrap();
let string = "name[BDC-OMNIChannel-Server-OUT]uuid[260b133c-6dfc-51eb-d0a5-eff41f9c9cea]srcintf[INT-To-CoreWAN TO-FG3700-DC-IC]dstintf[SERVICE-INT-OUTSIDE]srcaddr[Omni-Channel-Testbed]dstaddr[all]action[accept]schedule[always]service[DNS HTTP HTTPS PING]utm-status[enable]logtraffic[all]ippool[enable]poolname[INTERNET-SERVICES-OUTBOUND-POOL]profile-protocol-options[default]ssl-ssh-profile[certificate-inspection]ips-sensor[high_security]nat[enable]";
// 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/