// 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#"(?x) (?:
<
(?: p | li )
\b
[^>]*? color \s* : \s*
(?:
( black ) # (1)
# | transparent
)
[^>]*? >
# (?(1)
(?: \s* <span \b [^>]*? > )?
#)
|
<span \b
[^>]*? color \s* : \s* black [^>]*? >
)
(?s)
\s* <code \b
(?: ".*?" | '.*?' | [^>]*? )+ >
(*SKIP) (*FAIL)
|
<code \b
[^>]*? style [^>]*? background-color \s* : \s* transparent [^>]*? >"#).unwrap();
let string = "<p....color: black...> <span.......>
<code style=\"background-color: transparent;\">
<p....color: black...>
<code style=\"background-color: transparent;\">
<p....color: transparent...>
<code style=\"background-color: transparent;\">
<span....color: black...>
<code style=\"background-color: transparent;\">
<li style....color: black...> <span....color: black...>
<code style=\"background-color: transparent;\">
<li style....color: black...>
<code>
<li style....color: black...> <span......>
<code style=\"background-color: transparent;\">
<code style=\"background-color: transparent;\">
";
// 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/