rustHow to get all matches from a Rust regex?
To get all matches from a Rust regex, you can use the find_iter method on a Regex object. This method returns an iterator of Match objects, which can be used to access the matched text.
Example code
let re = Regex::new(r"\d+").unwrap();
let text = "123 456 789";
for m in re.find_iter(text) {
    println!("{}", m.as_str());
}
Output example
123
456
789
Code explanation
Regex::new(r"\d+"): creates a newRegexobject from the given regular expression.find_iter(text): returns an iterator ofMatchobjects from the given text.m.as_str(): returns the matched text as a string.
Helpful links
Related
- How to replace strings using Rust regex?
 - Regex example to match multiline string in Rust?
 - How to match whitespace with a regex in Rust?
 - How to match a URL with a regex in Rust?
 - How to split a string with Rust regex?
 - How to use non-capturing groups in Rust regex?
 - How to use negation in Rust regex?
 - How to use regex lookbehind in Rust?
 - How to use regex lookahead in Rust?
 - How to ignore case in Rust regex?
 
More of Rust
- How to use non-capturing groups in Rust regex?
 - Regex example to match multiline string in Rust?
 - How to match the end of a line in a Rust regex?
 - How to use regex captures in Rust?
 - How to use regex to match a double quote in Rust?
 - How to escape a Rust regex?
 - How to match all using regex in Rust?
 - How to perform matrix operations in Rust?
 - How to use regex lookbehind in Rust?
 - How to create a HashMap of structs in Rust?
 
See more codes...