Repository navigation
How do I get all the matches in repeat capture group? #1269
use regex::Regex;
fn main() {
let regex = Regex::new("((?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2}),?)+").unwrap();
for c in regex.captures_iter("2015-01-02,2025-12-24") {
println!("{c:?}");
for m in c.iter() {
println!("{m:?}");
}
}
}I'd expect to go over both "2015-01-02" and "2025-12-24", but it seems only the last group retains: |
Answered by
BurntSushi
May 20, 2025
Replies: 2 comments
|
You can't. I'm not sure why you would expect that. Most regex engines don't let you access repeated matches of a capture group within one single overall match. The You need to change your regex pattern or use additional regexes. |
0 replies
Answer selected by
BurntSushi
Well do you mean you need an output matches of |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't. I'm not sure why you would expect that. Most regex engines don't let you access repeated matches of a capture group within one single overall match. The
regexcrate does not allow it. It doesn't track the state necessary for such a thing.You need to change your regex pattern or use additional regexes.