// 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)\e\[([0-9;]*)m").unwrap();
let string = "watson -c8
[38;5;60m[7mWATSON[27m[38;5;60m Loaded es7s/commons[m
U+[m[94m[1m0[m [33m\\0[m[6n[90m │ [mU+[m[94m[1m10[m [31mDLE[mU+[m[94m[1m20[m [33m SP[mU+[m[94m[1m30[m [1m 0 [mU+[m[94m[1m40[m [1m @ [mU+[m[94m[1m50[m [1m P [mU+[m[94m[1m60[m [1m ` [mU+[m[94m[1m70[m [1m p [m
U+[m[94m[1m1[m [31mSOH[mU+[m[94m[1m11[m [31mDC1[mU+[m[94m[1m21[m [1m ! [mU+[m[94m[1m31[m [1m 1 [mU+[m[94m[1m41[m [1m A [mU+[m[94m[1m51[m [1m Q [mU+[m[94m[1m61[m [1m a [mU+[m[94m[1m71[m [1m q [m
U+[m[94m[1m2[m [31mSTX[mU+[m[94m[1m12[m [31mDC2[mU+[m[94m[1m22[m [1m \" [mU+[m[94m[1m32[m [1m 2 [mU+[m[94m[1m42[m [1m B [mU+[m[94m[1m52[m [1m R [mU+[m[94m[1m62[m [1m b [mU+[m[94m[1m72[m [1m r [m
U+[m[94m[1m3[m [31mETX[mU+[m[94m[1m13[m [31mDC3[mU+[m[94m[1m23[m [1m # [mU+[m[94m[1m33[m [1m 3 [mU+[m[94m[1m43[m [1m C [mU+[m[94m[1m53[m [1m S [mU+[m[94m[1m63[m [1m c [mU+[m[94m[1m73[m [1m s [m
U+[m[94m[1m4[m [31mEOT[mU+[m[94m[1m14[m [31mDC4[mU+[m[94m[1m24[m [1m $ [mU+[m[94m[1m34[m [1m 4 [mU+[m[94m[1m44[m [1m D [mU+[m[94m[1m54[m [1m T [mU+[m[94m[1m64[m [1m d [mU+[m[94m[1m74[m [1m t [m
U+[m[94m[1m5[m [31mENQ[mU+[m[94m[1m15[m [31mNAK[mU+[m[94m[1m25[m [1m % [mU+[m[94m[1m35[m [1m 5 [mU+[m[94m[1m45[m [1m E [mU+[m[94m[1m55[m [1m U [mU+[m[94m[1m65[m [1m e [mU+[m[94m[1m75[m [1m u [m
U+[m[94m[1m6[m [31mACK[mU+[m[94m[1m16[m [31mSYN[mU+[m[94m[1m26[m [1m & [mU+[m[94m[1m36[m [1m 6 [mU+[m[94m[1m46[m [1m F [mU+[m[94m[1m56[m [1m V [mU+[m[94m[1m66[m [1m f [mU+[m[94m[1m76[m [1m v [m
U+[m[94m[1m7[m [33m\\a[mU+[m[94m[1m17[m [31mETB[mU+[m[94m[1m27[m [1m ' [mU+[m[94m[1m37[m [1m 7 [mU+[m[94m[1m47[m [1m G [mU+[m[94m[1m57[m [1m W [mU+[m[94m[1m67[m [1m g [mU+[m[94m[1m77[m [1m w [m
U+[m[94m[1m8[m [33m\\b[mU+[m[94m[1m18[m [31mCAN[mU+[m[94m[1m28[m [1m ( [mU+[m[94m[1m38[m [1m 8 [mU+[m[94m[1m48[m [1m H [mU+[m[94m[1m58[m [1m X [mU+[m[94m[1m68[m [1m h [mU+[m[94m[1m78[m [1m x [m
U+[m[94m[1m9[m [33m\\t[mU+[m[94m[1m19[m [31mEM[mU+[m[94m[1m29[m [1m ) [mU+[m[94m[1m39[m [1m 9 [mU+[m[94m[1m49[m [1m I [mU+[m[94m[1m59[m [1m Y [mU+[m[94m[1m69[m [1m i [mU+[m[94m[1m79[m [1m y [m
U+[m[94m[1mA[m [33m\\n[mU+[m[94m[1m1A[m [31mSUB[mU+[m[94m[1m2A[m [1m * [mU+[m[94m[1m3A[m [1m : [mU+[m[94m[1m4A[m [1m J [mU+[m[94m[1m5A[m [1m Z [mU+[m[94m[1m6A[m [1m j [mU+[m[94m[1m7A[m [1m z [m
U+[m[94m[1mB[m [33m\\v[mU+[m[94m[1m1B[m [31mESC[mU+[m[94m[1m2B[m [1m + [mU+[m[94m[1m3B[m [1m ; [mU+[m[94m[1m4B[m [1m K [mU+[m[94m[1m5B[m [1m [ [mU+[m[94m[1m6B[m [1m k [mU+[m[94m[1m7B[m [1m { [m
U+[m[94m[1mC[m [33m\\f[mU+[m[94m[1m1C[m [31mFS[mU+[m[94m[1m2C[m [1m , [mU+[m[94m[1m3C[m [1m < [mU+[m[94m[1m4C[m [1m L [mU+[m[94m[1m5C[m [1m \\ [mU+[m[94m[1m6C[m [1m l [mU+[m[94m[1m7C[m [1m | [m
U+[m[94m[1mD[m [33m\\r[mU+[m[94m[1m1D[m [31mGS[mU+[m[94m[1m2D[m [1m - [mU+[m[94m[1m3D[m [1m = [mU+[m[94m[1m4D[m [1m M [mU+[m[94m[1m5D[m [1m ] [mU+[m[94m[1m6D[m [1m m [mU+[m[94m[1m7D[m [1m } [m
U+[m[94m[1mE[m [31mSO[mU+[m[94m[1m1E[m [31mRS[mU+[m[94m[1m2E[m [1m . [mU+[m[94m[1m3E[m [1m > [mU+[m[94m[1m4E[m [1m N [mU+[m[94m[1m5E[m [1m ^ [mU+[m[94m[1m6E[m [1m n [mU+[m[94m[1m7E[m [1m ~ [m
U+[m[94m[1mF[m [31mSI[mU+[m[94m[1m1F[m [31mUS[mU+[m[94m[1m2F[m [1m / [mU+[m[94m[1m3F[m [1m ? [mU+[m[94m[1m4F[m [1m O [mU+[m[94m[1m5F[m [1m _ [mU+[m[94m[1m6F[m [1m o [mU+[m[94m[1m7F[m [31mDEL[m[6n[90m │ [m
";
// 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/