// 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".+left X:..(.+?)\n.+Y:..(.+?)\n.+\n.+\n.+:.(.+?)\n.+:.(.+?)\n").unwrap();
let string = "
xwininfo: Window id: 0x4800024 \"Yebe\"
Absolute upper-left X: 100
Absolute upper-left Y: 164
Relative upper-left X: 10
Relative upper-left Y: 45
Width: 1600
Height: 1200
Depth: 24
Visual: 0x6e
Visual Class: DirectColor
Border width: 0
Class: InputOutput
Colormap: 0x4800022 (not installed)
Bit Gravity State: ForgetGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +100+164 -860+164 -860-76 +100-76
-geometry 1600x1200+90-66";
// 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/