// 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"#[a-f0-9]{6}(?:,\s*#[a-f0-9]{6})?").unwrap();
let string = "style=\\\"color: rgb(255,0,24)\\\"
style=\\\"color: rgb(255, 0, 24)\\\"
style=\\\"color: rgba(255, 0, 24, .5)\\\"
style=\\\"color: hsla(170, 23%, 25%, 0.2 )\\\"
style=\\\"color: #fff\\\"
style=\\\"color: #f2ewq\\\" this isn\\'t a color
style=\\\"color: #0f243e\\\"
style=\\\"color: #0f243e,#3f54ae\\\"
style=\\\"color: #0f243eпп\\\" здесь кириллические буквы пропустило
style=\\\"color: #0f243eбб,#3f54aeпп\\\" здесь кириллические буквы пропустило
style=\\\"color: 0x00ffff\\\" This is a color with the `#` escaped
.foo{
color: rgb(255,0,24);
color: rgb(255, 0, 24);
color: rgba(255, 0, 24, .5);
color: hsla(170, 23%, 25%, 0.2 );
color: #fff;
color: rgba(#fff, .5) This shows it works with SASS
color: #f2ewq; this isn\\'t a color
color: 0f243e;
color: #0f243e,#3f54ae;
color: 0x00ffff; This is a color with the `#` escaped
}";
// result will be a tuple containing the start and end indices for the first match in the string
let result = regex.captures(string);
let (start, end) = match result {
Some((s, e)) => (s, e),
None => {
// ...
}
};
println!("{}", &string[start, end]);
}
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/