Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Method not found in `regex::Captures<'_>`

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).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading