// 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)<Device(?:(?!<\/Device).)*<Block[^>]+Name="ZG123CZ123".*?<\/Device>"#).unwrap();
let string = "<Device DevID=\"14212111\" Model=\"\" GroupID=\"\">
<Block Name=\"ZG123CZ123\" LastFileDld=\"\" LastFullDld=\"\">
<Group ZD=\"1\">
<DSize ParamName=\"KEY\" Value=\"RAM\"/>
<DSize ParamName=\"REM\" Value=\"***\"/>
<DSize ParamName=\"*UNZIP\" Value=\"I:ZG123CZ123.ZIP\"/>
</Group>
<Group ZD=\"15\">
<DSize ParamName=\"REM\" Value=\"=\"***\"\"/>
<DSize ParamName=\"#DEBUGPORT\" Value=\"\"/>
</Group>
</Block>
<DevFiles />
</Device>
<Device DevID=\"14212111\" Model=\"\" GroupID=\"\">
<Block Name=\"DG\" LastFileDld=\"\" LastFullDld=\"\">
<Group ZD=\"3\">
<DSize ParamName=\"*UNZIP\" Value=\"DG.ZIP\"/>
<DSize ParamName=\"*GO\" Value=\"F:DG.OUT\"/>
</Group>
<Group ZD=\"15\">
<DSize ParamName=\"#LOGPORT\" Value=\"NONE\"/>
<DSize ParamName=\"CDH6\" Value=\"\"/>
</Group>
</Block>
<DevFiles />
</Device>
<Device DevID=\"14212111\" Model=\"\" GroupID=\"\">
<Block Name=\"ZG123CZ123\" LastFileDld=\"\" LastFullDld=\"\">
<Group ZD=\"1\">
<DSize ParamName=\"KEY\" Value=\"RAM\"/>
<DSize ParamName=\"REM\" Value=\"***\"/>
<DSize ParamName=\"*UNZIP\" Value=\"I:ZG123CZ123.ZIP\"/>
</Group>
<Group ZD=\"15\">
<DSize ParamName=\"REM\" Value=\"=\"***\"\"/>
<DSize ParamName=\"#DEBUGPORT\" Value=\"\"/>
</Group>
</Block>
<DevFiles />
</Device>";
// 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/