// 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)(datasource=\"([^"]*)\")(?!.+\1)"#).unwrap();
let string = " <cfquery name=\"qry_getEvent\" datasource=\"#APPLICATION.firstDSN#\">
SELECT *
FROM events
WHERE id = 1
</cfquery>
<cfquery name=\"qry_getPlayers\" datasource=\"#APPLICATION.firstDSN#\">
SELECT *
FROM players
WHERE event_id = 1
</cfquery>
<cfquery name=\"qry_getLocation\" datasource=\"secondDSN\">
SELECT *
FROM locations
WHERE event_id = 1
</cfquery>";
// 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/