diff --git a/nmpolicy/internal/expander/state_expander.go b/nmpolicy/internal/expander/state_expander.go index 66eca170..3cfd287c 100644 --- a/nmpolicy/internal/expander/state_expander.go +++ b/nmpolicy/internal/expander/state_expander.go @@ -81,24 +81,30 @@ func (c StateExpander) expandMap(mapState map[string]interface{}) (map[string]in } func (c StateExpander) expandString(stringState string) (interface{}, error) { - re := regexp.MustCompile(`^{{ (.*) }}$`) + re := regexp.MustCompile(`^{{ (.*) }}(\.[0-9]+)?$`) submatch := re.FindStringSubmatch(stringState) if len(submatch) == 0 { return stringState, nil } - const captureSubmatchLength = 2 + const captureSubmatchLength = 3 if len(submatch) != captureSubmatchLength { return nil, fmt.Errorf("the capture expression has wrong format %s", stringState) } capturePath := submatch[1] + suffix := submatch[2] resolvedPath, err := c.capResolver.ResolveCaptureEntryPath(capturePath) if err != nil { return nil, err } + switch captureValue := resolvedPath.(type) { + case string: + resolvedPath = captureValue + suffix + } + return resolvedPath, nil }