Help with Regex in Rust

I'm porting a lib from JS to Rust (Yet Another..). There is a Regex in this library:

const REGEXP = /(\w+)=("[^"]*")/g;

Which will try to find a match in this string: error="invalid_token", error_description="bad things are happening"

Regex match

I have a rust code that is as follows.
This does not find any match with in the the above string.
Is there something wrong with the rust code?

    let regex = Regex::new(r#"/(\w+)=("[^"]*")/g"#).unwrap();
    for m in
        regex.find_iter("error=\"invalid_token\", error_description=\"bad things are happening\"")
        let a = m;

/.../flags is a regex builder. Those characters are not part of the regular expression itself (you're not looking for literal / or gs).

The g flag just means "match multiple times", which is inherent in find_iter. So:

let regex = Regex::new(r#"(\w+)=("[^"]*")"#).unwrap();

(You might actually want captures_iter or the like.)


Oh my...I was so blind...This works..Thanks

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.