// 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"(?s)\[(?P<stanza_name>[0-9a-zA-Z-_\ ]*?)\](?P<text>.*?)\n\n").unwrap();
let string = "[inv_records]
search = index=apm_main eventtype=da_host sourcetype=snpm:ipact:kvp2
[equipment-InterfaceStatsLogRecord]
search = eventtype=sam_events (ds=equipment.InterfaceStatsLogRecord OR ds=equipment.InterfaceAdditionalStats)
[inv_avc]
search = eventtype=inv_records source=\"/data/snpm/splunk/inventory/*_AVC_*\" ACCESS_SERVICE_TECH_TYPE=\"*\"\\
[inv_cvc]
search = eventtype=inv_records source=\"/data/snpm/splunk/inventory/*SNPM_CVC_*\"
[inv_device_links]
search = eventtype=inv_records source=\"/data/snpm/splunk/inventory/*_DEVICE_LINKS_*\"\\
[inv_nni]
search = eventtype=inv_records source=\"/data/snpm/splunk/inventory/*_NNI_*\" NOT source=\"*IPACT_SNPM_NNI_LINKS*\"\\
[inv_rsp_cvc_interconnect_svc]
search = eventtype=inv_records source=\"/data/snpm/splunk/inventory/*_RSP_CVC_INTERCONNECT_SVC_*\"\\
[inv_sites_poi]
search = eventtype=inv_records source=\"/data/snpm/splunk/inventory/*_SITES_POI_*\"\\
[service-CombinedForwardingPlaneQueueGroupServiceIngressLogRecord]
search = eventtype=sam_events ds=service.CombinedForwardingPlaneQueueGroupServiceIngressLogRecord
[sam_events]
search = index=apm_main eventtype=da_host sourcetype=snpm:sam:kvp*
[service-CombinedQueueGroupEgressLogRecord]
search = eventtype=sam_events ds=service.CombinedQueueGroupEgressLogRecord
[service-ServiceEgressOctetsLogRecord]
search = eventtype=sam_events ds=\"service.ServiceEgressOctetsLogRecord\"
[summary_snr_histogram]
search = (index=\"summary_apm_snr\" eventtype=search_head) OR (eventtype=\"summary_data\") snpm_type=\"SNR UTIL\"
[summary_cvc_util]
search = (index=\"summary_apm_cvc\" eventtype=search_head) OR (eventtype=\"summary_data\") snpm_type=\"CVC UTIL\"
[savvi_log]
search = index=apm_main eventtype=da_host (source=\"/var/log/savvi/*\" OR source=\"/opt/titan/log/*\")
[summary_data]
search = (index=\"apm_snpm\" eventtype=search_head) search_name=\"*summary*\"
[summary_ipact]
search = (index=\"summary_apm_ipact\" eventtype=search_head) OR (eventtype=\"summary_data\") snpm_type=\"IPACT_CVC\"
[summary_ipact_avc]
search = (index=\"summary_apm_ipact\" eventtype=search_head) OR (eventtype=\"summary_data\") snpm_type=\"IPACT_AVC\"
[summary_cvc_bh]
search = (index=\"summary_apm_cvc\" eventtype=search_head) OR (eventtype=\"summary_data\") snpm_type=\"CVC BH\"
[summary_enni_group]
search = (index=\"summary_apm_enni\" eventtype=search_head) OR (eventtype=\"summary_data\") snpm_type=\"ENNI UTIL GRP\"
[summary_enni_port]
search = (index=\"summary_apm_enni\" eventtype=search_head) OR (eventtype=\"summary_data\") snpm_type=\"ENNI UTIL PRT\"
[sam_enni_port]
search = (eventtype=sam_events ds=\"equipment.InterfaceAdditionalStatsLogRecord\" displayedName=\"Port*\" NOT (suspect=true) )
[sam_enni_group]
search = (eventtype=sam_events ds=\"equipment.InterfaceAdditionalStatsLogRecord\" displayedName=\"Lag*\" NOT (suspect=true) )
[summary_sanitized]
search = ( eventtype=summary_cvc_util inboundUtilizationPcnt>= 0 inboundUtilizationPcnt< 200 ) OR\\
( eventtype=summary_snr_histogram utilPcnt>=0 utilPcnt<200 ) OR\\
( eventtype=summary_enni* (rx_utilPcnt>=0 rx_utilPcnt<200 ) (tx_utilPcnt>=0 tx_utilPcnt<200 )) OR\\
( eventtype=summary_cvc_util NOT inboundUtilizationPcnt=* ) OR\\
( eventtype=summary_snr_histogram NOT utilPcnt=* ) OR\\
( eventtype=summary_enni* (NOT rx_utilPcnt=*) OR (NOT tx_utilPcnt=*))
[sam_cvc_downstream_1_1]
search = eventtype=sam_events ds=service.CombinedForwardingPlaneQueueGroupServiceIngressLogRecord
[sam_cvc_downstream_n_1]
search = eventtype=sam_events ds=\"service.ServiceEgressOctetsLogRecord\" svcId=* (policerId=6) NOT (statMode=no-stats)
[sam_cvc_upstream_1_1]
search = eventtype=sam_events ds=\"service.ServiceEgressOctetsLogRecord\" sapId=\"lag-*\" NOT statMode=\"no-stats\"
[sam_cvc_upstream_n_1]
search = eventtype=sam_events ds=\"service.ServiceEgressOctetsLogRecord\" queueId=6 sapId=\"lag*\"
[summary_filter]
search = ( eventtype=summary_cvc_util inboundUtilizationPcnt < 0 OR inboundUtilizationPcnt> 200 ) OR\\
( eventtype=summary_snr_histogram utilPcnt < 0 OR utilPcnt >200 ) OR\\
( eventtype=summary_enni* (rx_utilPcnt < 0 OR rx_utilPcnt>200 ) OR (tx_utilPcnt<0 tx_utilPcnt>200 ))
[inv_nni_links]
search = eventtype=inv_records source=\"*IPACT_SNPM_NNI_LINKS*\"
[sam_ltss]
priority = 5
search = index=apm_main eventtype=ltss_da_host ds=service.ServiceEgressOctetsLogRecord
[ltss_inv_sites_poi]
search = eventtype=ltss_inv_records source=\"*_SITES_PO*\"\\
[ltss_inv_rsp_cvc_interconnect_svc]
search = eventtype=ltss_inv_records source=\"*_RSP_CVC_INTERCONNECT_SVC_*\"\\
[ltss_inv_records]
priority = 5
search = index=apm_main sourcetype = snpm:ipact:kvp2 eventtype=ltss_da_host
[ltss_inv_nni_links]
search = eventtype=ltss_inv_records source=\"*IPACT_SNPM_NNI_LINKS*\"
[ltss_inv_nni]
search = eventtype=ltss_inv_records source=\"*IPACT_SNPM_NNI*\" NOT source=\"*IPACT_SNPM_NNI_LINKS*\"\\
[ltss_inv_device_links]
search = eventtype=ltss_inv_records source=\"*IPACT_SNPM_DEVICE_LINKS*\"\\
[ltss_inv_cvc]
search = eventtype=ltss_inv_records source=\"*IPACT_SNPM_CVC*\"
[ltss_inv_avc]
search = eventtype=ltss_inv_records source=\"*IPACT_SNPM_AVC*\" ACCESS_SERVICE_TECH_TYPE=\"Satellite\"\\
[ltss_summary_ipact_avc]
search = eventtype=ltss_summary_data index=\"summary_apm_ltss_ipact\" snpm_type=\"IPACT_AVC_LTSS\"
[ltss_summary_cvc_util]
search = eventtype=ltss_summary_data index=summary_apm_ltss_cvc snpm_type = \"LTSS CVC UTIL\" snpm_version=\"V1.3\"
[ltss_summary_avc_util_daily]
search = eventtype=ltss_summary_data index=summary_apm_ltss_avc_daily snpm_type = \"LTSS AVC UTIL DAILY\" snpm_version=\"V1.5.1\"
[ltss_summary_avc_util]
search = eventtype=ltss_summary_data index=summary_apm_ltss_avc snpm_type = \"LTSS AVC UTIL\" snpm_version=V1.5
[ltss_summary_cvc_util_breach]
priority = 5
search = eventtype=ltss_summary_data index=summary_apm_ltss_cvc snpm_type=\"CVC UTIL BREACH\"
[ltss_summary_short_term]
search = eventtype=ltss_summary_data index=summary_apm_ltss snpm_type = \"LTSS SHORT TERM\"
[ltss_summary_fsd_fsr]
search = eventtype=ltss_summary_data index=summary_apm_ltss snpm_type=\"LTSS FSD FSR DAILY\"
[ltss_summary_data]
search = (index=summary_apm_ltss* (eventtype=search_head))
[ltss_summary_beam_util]
search = eventtype=ltss_summary_data snpm_type = \"LTSS BEAM UTIL\" snpm_version=\"V1.5.2\"
[search_head]
search = (host=svsss0000003np-heavy OR host=svsss0000203np-heavy)
[da_host]
search = (host=svapm0000004np)
[ltss_da_host]
search = (host=svapm0000004np)
[sam_aas]
priority = 5
search = index=apm_main host=svapm0000008ee sourcetype=\"snpm:sam:kvp2\" ds=\"service.ServiceEgressOctetsLogRecord\"
[aas_summary_enni_group]
priority = 5
search = (index=\"summary_apm_enni\" eventtype=search_head) OR (eventtype=\"aas_summary_data\") snpm_type=\"AAS ENNI UTIL GRP\"
[aas_avc_status_daily]
search = index=apm_snpm snpm_type=\"AAS_IPACT_AVC_STATUS\"
[snpm_inv_avc]
search = eventtype=snpm_inv_records source=\"*IPACT_SNPM_AVC*\"
[snpm_inv_cvc]
search = eventtype=snpm_inv_records source=\"*IPACT_SNPM_CVC*\"
[snpm_inv_rsp_cvc_interconnect_svc]
search = eventtype=snpm_inv_records source=\"*_RSP_CVC_INTERCONNECT_SVC_*\"
[snpm_inv_nni]
search = eventtype=snpm_inv_records source=\"*IPACT_SNPM_NNI*\" NOT source=\"*IPACT_SNPM_NNI_LINKS*\"
[snpm_inv_records]
search = index=apm_main sourcetype=snpm:ipact:kvp2 eventtype=da_host
[snpm_inv_sites_poi]
search = eventtype=snpm_inv_records source=\"*_SITES_PO*\"
[snpm_summary_ipact_avc]
search = index=\"summary_apm_ipact\" snpm_info=\"Ipact Summary for AVC SNPM\" (eventtype=search_head)
[aes_summary_ipact_avc]
search = index=\"summary_apm_ipact\" snpm_info=\"Ipact Summary for AVC SNPM\" ACCESS_SERVICE_TECH_TYPE=\"Fibre\" (eventtype=search_head)
[aes_avc_status]
search = index=\"summary_apm_ipact\" snpm_type=\"SNPM_IPACT_AVC_STATUS\" ACCESS_SERVICE_TECH_TYPE=\"Fibre\" (eventtype=search_head)
[aes_summary_ipact_cvc]
search = index=\"summary_apm_ipact\" snpm_type = \"IPACT_CVC_NNI_AES\" (eventtype=search_head)
[aes_cvc_status]
search = index=\"summary_apm\" snpm_type=\"IPACT_CVC_STATUS_AES\" (eventtype=search_head)
[aes_nni_status_summary]
search = index=\"summary_apm\" snpm_type=\"NNI_STATUS_AES\" (eventtype=search_head)
[aes_inni_summary_util_discard_status_combined]
search = index=\"summary_apm\" snpm_type=\"inni_summary_combined_aes\" (eventtype=search_head)
[aes_inni_summary]
search = index=\"summary_apm\" snpm_type=\"inni_group_summary_aes\" (eventtype=search_head)
[aes_enni_summary]
search = index=\"summary_apm\" snpm_type=\"enni_group_summary_aes\" (eventtype=search_head)
[sam_inni_group]
search = (eventtype=sam_events ds=\"equipment.InterfaceAdditionalStatsLogRecord\" displayedName=\"Lag*\" NOT (suspect=true) )
[aas_sam_inni_group]
search = (eventtype=aas_sam_events ds=\"equipment.InterfaceAdditionalStatsLogRecord\" displayedName=\"Lag*\" NOT (suspect=true) )\\
[aas_sam_events]
priority = 5
search = index=apm_main eventtype=da_host sourcetype=snpm:sam:kvp*
[aas_sam_enni_group]
priority = 5
search = eventtype=aas_sam_events ds=\"equipment.InterfaceAdditionalStatsLogRecord\" displayedName=\"Lag*\" NOT (suspect=true)
[aes_egress_drop]
search = eventtype=sam_events ds=\"Service.NetworkEgressOctetsLogRecord\"
[aes_egress_discard]
search = index=\"summary_apm\" snpm_type=\"aes_egress_discard\"
[ltss_summary_fsd_fsr_enhance]
search = eventtype=ltss_summary_data index=summary_apm_ltss snpm_type=\"LTSS FSD FSR DAILY ENHANCE\"
[ltss_summary_short_term_enhance]
search = eventtype=ltss_summary_data index=summary_apm_ltss snpm_type = \"LTSS SHORT TERM ENHANCE\"
[aes_summary_ipact_avc_device]
search = index=\"summary_apm_ipact\" snpm_info=\"Ipact Summary for AVC SNPM & Device Links\" ACCESS_SERVICE_TECH_TYPE=\"Fibre\" (eventtype=search_head)
[aes_avc_util_discard_summary]
search = index=\"summary_apm_avc\" snpm_type =\"AES AVC UTIL & DISCARD ALL\" (eventtype=search_head)
[ltss_summary_ipact_avc_30mintest]
search = eventtype=ltss_summary_data index=\"summary_apm_ltss_ipact\" snpm_type=\"IPACT_AVC_LTSS_30MIN\"
";
// 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/