// 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"(?m)\x1B\[(?:[0-9]{1,3}(?:;[0-9]{1,3})?)?[mGK]").unwrap();
let string = "Summary [0m
Accounts:
Name Account ID Title
----------------------------------------------- ------------ -----------------------------------------------
[32maccount-accountType-gamma[0m [38;2;128;128;128m123456789012[0m account-accountType-gamma
[32maccount-accountType-e2e-gamma[0m [38;2;128;128;128m123456789012[0m account-accountType-e2e-gamma
Summary [0m
Accounts:
Name Account ID Title
---------------------------------------------- ------------ ----------------------------------------------
[32maccount-accountType-e2e-prod[0m [38;2;128;128;128m123456789012[0m account-accountType-e2e-prod
[32maccount-accountType-prod[0m [38;2;128;128;128m123456789012[0m account-accountType-prod";
// 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/