No way to get captures names from Captures<'t>?

Hi all,

How can you get the capture names of a Regex you don't know beforehand ?

It seems not possible from a sole Captures<'t> struct. You can access captured values by index, so it's perfectly ok for unnamed capture groups. And access by name provided you already know the capture group name.

The only way I found is to get back to the Regex structure with the captures_names() method. But if you only have the Captures<'t> you've got from the captures() method, it seems impossible. However, this information is found in a Captures<'t> struct.

I'm using a function which is only returning a Captures<'t> struct, but not the original re.

Any hint welcome :wink:

You can iterate over the captures: Captures::iter, but there isn't a way to get the names of captures.

So I guess the only efficient way is to keep the original re and get names through captures_names().

Yeah, looks like it

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.