// 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"(?:CN=)(\w+)").unwrap();
let string = "CN=Lst-niketech.cis.splunk.admins,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-niketech.cis.splunk.users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.SOC,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=ACL.Shareddata.CIS.Shared.Operations.WHQ.Change,OU=ACL,OU=Groups,DC=ad,DC=nike,DC=com|CN=Shareddata.CIS.Shared.WHQ.Change,OU=SharedData,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.Information.Security.Incident.Reporting.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-digitaltech.splunk.security.users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-digitaltech.splunk.security.lead,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Application.SolarWinds.Xerox.Nike.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Citrix.Nike.Employees.Users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Nike.NikeTech.NIS.SecOps,OU=Nike,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Splunk.CIS.Admin.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=lst-Nike.Cloud.Change.Management,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Application.TimeTrack.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.nismonitor.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.SCCM.Reporting.AM,OU=SCCM,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Casper.Report.User,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.HR.Portal.ESS.NonRetail,OU=Portal,DC=ad,DC=nike,DC=com|CN=Application.HR.Portal.ESS.US,OU=Portal,DC=ad,DC=nike,DC=com|CN=Application.Hightail.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-FE.All,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-All.Exchange.Mailboxes BEAVERTN-SVR-VB,OU=Lists,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Citrix.WebEx.Users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.ITSecurity.All,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-Metaframe.Global.Users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=SharedData.GIPS_AllStar.WHQ.Read,OU=SharedData,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.citrix.shared.webex.users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.SecOps,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=SharedMail.Firewall.Changes.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.Nike.Information.Security.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.IOS.SSLCert.Requests.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com";
// 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/