- 
  Notifications
 
You must be signed in to change notification settings  - Fork 483
 
 
 How do I get the name for each capture group when using Captures::iter?
 
 #1268
 
 
 -
Today I wrota program to catch group capture in a generic way:
let mut result = vec![]; for c in regex.captures_iter(arg) { let mut cap = vec![]; for m in c.iter() { if let Some(m) = m { // how to get the name? cap.push(<{ "name": ..., "text": m.as_str() }>); } cap.push(<null>); } result.push(cap); }
When the match is not named, I'm OK to attach a null name field. But is it possible to get the name of named capture group?
Related - #955 and thus cc @BurntSushi @01mf02
Beta Was this translation helpful? Give feedback.
All reactions
 
 
 Answered by
 
 BurntSushi
 
 
 
 May 19, 2025 
 
 
 In the future, please provide an MRE.
It looks like you should be able to just do for (name, m) in regex.capture_names().zip(c.iter()) { via Regex::capture_names.
Replies: 1 comment 1 reply
-
In the future, please provide an MRE.
It looks like you should be able to just do for (name, m) in regex.capture_names().zip(c.iter()) { via Regex::capture_names.
Beta Was this translation helpful? Give feedback.
All reactions
 
 1 reply
 
 
 -
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions
 Answer selected by
 BurntSushi
 
 Sign up for free
 to join this conversation on GitHub.
 Already have an account?
 Sign in to comment