witty-holiday-65473
02/04/2024, 4:43 PMMatchContext
via a new field: RegexpNamedCaptureGroups
. Currently, MatchContext
has a field: RegexpCaptureGroups
but this field only (naively?) sets capture groups to a []string
with no reference to the regexp group the capture is associated. My enhancement adds RegexpNamedCaptureGroups map[string]string
to MatchContext
and populates the map based on the groups captured and their values. The groups include all numbered and named groups; similar to FindStringSubmatch
, group "0" is skipped. The result map can be used to look up "named" as well as numerical e.g., "1" capture groups. These can then be accessed within text {{ print "templates" }}
within config files. I feel this can be carried over into use within jsonnet.
As an example, a config can contain a regexp url match rule such as: <https://example.com/><<(?<id>[-0-9a-fA-F]+)>>
and within that same rule, any text templates can refer to .MatchContext.RegexpNamedCaptureGroups.id
or index .MatchContext.RegexpNamedCaptureGroups "id"
.
My changes enable this construct.