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.
      
      
          Answered by
          
            BurntSushi
          
      
      
        May 19, 2025 
      
    
    Replies: 1 comment 1 reply
-
| In the future, please provide an MRE. It looks like you should be able to just do  | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
      Answer selected by
        BurntSushi
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
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()) {viaRegex::capture_names.