How do I shorten my Rust code to get integer values from regex named capture groups?
regex::Captures provides a handy implementation of Index&lt;&amp;str&gt;. This lets you pull named matches out with caps[name]. Combine that with a few std APIs and you can write the same code like this:

use regex::Regex;

fn main() -&gt; Result&lt;(), Box&lt;dyn std::error::Error&gt;&gt; {
    let re = Regex::new(concat!(
        r"^\s+(?P&lt;qrw1&gt;\d+)\|(?P&lt;qrw2&gt;\d+)",
        r"\s+(?P&lt;arw1&gt;\d+)\|(?P&lt;arw2&gt;\d+)",
    ))
    .unwrap();
    let names = ["qrw1", "qrw2", "arw1", "arw2"];
    let buffer = " 0|1 2|3\n 4|5 6|7\n 8|9 10|11\n";

    let mut maximums = [0i32; 4];

    for caps in buffer.lines().filter_map(|line| re.captures(line)) {
        for (&amp;name, max) in names.iter().zip(&amp;mut maximums) {
            *max = std::cmp::max(*max, caps[name].parse()?);
        }
    }
    for (&amp;name, max) in names.iter().zip(&amp;maximums) {
        println!("max {}: {:.2}", name, max);
    }

    Ok(())
}
```