Closed thangld322 closed 4 years ago
If you want to support multiple matches you could also filter the names
first before checking the captures so you don't filter it each time. Other than that it would appear this is the best current method to get a map[string]string
of only named groups and storing the first capture.
If you need this in a super-hot code path you could make an optimized fork to use the internal Regexp.capnames
map to skip a lot of the logic since that map only contains named groups (no filtering needed). The keys would be exactly what you wanted and the values could be used to call mat.GroupByNumber()
Sorry this took so long to reply, it just fell off my radar and I didn't notice it until today.
I'm trying to use this library to get all the named captured groups to a map[string]string. This is my code:
Is this the best way in term of performance to do it? First it calls FindStringMatch(), then it calls Groups() and finally, a
for
loop. Seem a little too many jobs to do. :D