regex get names

Dmitry Olshansky dmitry.olsh at
Wed Feb 8 03:40:23 PST 2012

On 08.02.2012 13:44, James Miller wrote:
> I posted something similar learn, but since this is a request, not a
> question I'm going to reiterate it here.
> After looking through std.regex, it would be useful if there was a way
> to get the names of the named matches from the Captures. e.g. R[] names
> = m.getNames(). With the idea being that each name is one of the named
> sub-expressions from (?P<name>...).
> I could probably make the change myself, but I want to get any opinions
> on why this is not a good idea before doing so.

Actually I believe it's a question of adding some introspection 
methods/properties to Regex struct. That's something we need - names, 
number of captures and number <---> name correspondence.

As for the request as is, when returning plain arrays for internals of 
objects I'm weary of one thing - it's either
a) aliasing as const(R)[]
b) duping the the internal array / allocating and filling a new one

As long as internals of Regex are GC allocated and slicable we're fine 
with a). The b) option can get nasty as it adds overhead for innocently 
looking operations though they shouldn't be frequent.

Personally, I'm more into returning a thin wrapped random-access range, 
that could be just map!""(dict), more importantly it can change 
it's mechanics later on.

Dmitry Olshansky

More information about the Digitalmars-d mailing list