Why do my regex matches have 2 instances of one group?

I have this regex to pull two pieces of information from each method overload declaration in a class. The methods all look like this:
public bool RetrieveServiceCache(service_cache service_Cache, ref DocumentModelFailureCount responseCache, ref String sLog)`

public bool RetrieveServiceCache(service_cache service_Cache, ref DocumentModelFailureCount responseCache, ref LogHelper logHelper)
public bool RetrieveServiceCache(service_cache service_Cache, ref DocumentModelFailureCount responseCache, ref String sLog)`

public bool RetrieveServiceCache(service_cache service_Cache, ref DocumentModelFailureCount responseCache, ref LogHelper logHelper)
Most overloads occur twice, once with a String sLog logger, and once with a LogHelper logHelper logger, and there are a total of about 32 overloads, each one having a different type for the responseCache parameter, like the example above has DocumentModelFailureCount. I want to extract a list with two entries for each responseCache type, one for each type of logger. I basically want a list that looks like this:
DocumentModelFailureCount, sLog
DocumentModelFailureCount, logHelper
SomeOtherResponseCacheType, sLog
SomeOtherResponseCacheType, logHelper
DocumentModelFailureCount, sLog
DocumentModelFailureCount, logHelper
SomeOtherResponseCacheType, sLog
SomeOtherResponseCacheType, logHelper
I've "engineered" this regex on regex101.com, and it seems to work nicely, except for one curiosity:"
public bool RetrieveServiceCache\(service_cache service_Cache, ref (?'respType'\w+) responseCach.*(?'logType'(sLog|logHelper))\)
public bool RetrieveServiceCache\(service_cache service_Cache, ref (?'respType'\w+) responseCach.*(?'logType'(sLog|logHelper))\)
Each match shows the whole declaration header, and both named groups, but it also shows the logType group as a numbered group: Match 1: public bool RetrieveServiceCache(service_cache service_Cache, ref NIISResponse responseCache, ref String sLog) - Group 1: sLog - Group respType: NIISResponse - Group logType: sLog Why does only one named group also appear as a numbered group?
1 Reply
VoidPointer
VoidPointerOP2w ago
Shit, sorry, I had so much uphill trying to get it right, but I'll try again. Oh, thanks! I thought the alternation needed its own parens. I'll try stick to <> for names as well.

Did you find this page helpful?