When I run this code in playground:
use regex::Regex;
fn main() {
let re = Regex::new(r#"regex(group)"#).unwrap();
println!("{:?}", re.captures(r#"regexgroup"#).unwrap().get(1).unwrap().as_str());
}
the code snippet works. However, running this code locally I get the error:
error[E0599]: no method named `get` found for struct `regex::Captures` in the current scope
|
| println!("{:?}", re.captures(r#"regexgroup"#).unwrap().get(1).unwrap().as_str());
| ^^^ method not found in `regex::Captures<'_>`
In both cases I am using the 2018 edition of Rust and import regex::Regex (and nothing else from the regex crate).
I tried using cargo clean and importing the mentioned Struct but nothing works. In the regex doc they basically do the above thing and it definitely implements the get method.
>Solution :
You got an old version of regex. Up until v0.1.80 (and including), it did not have get(). Upgrade your regex version (change Cargo.toml to at least regex = "1"), or use the pos() method – the name of the early get(), or just use indexing since you unwrap() anyway.