Add named capture group tests

This commit is contained in:
2025-03-26 12:13:18 +01:00
parent b63b4d1352
commit a8c2257f20
2 changed files with 797 additions and 0 deletions

View File

@@ -145,6 +145,19 @@ func (p *RegexProcessor) ProcessContent(content string, pattern string, luaExpr
continue
}
namedCaptures := make(map[string]string)
groupNames := compiledPattern.SubexpNames()
for i, name := range groupNames {
if i == 0 {
continue
}
if i < len(match) {
namedCaptures[name] = string(match[i])
}
}
log.Printf("Named captures: %v", namedCaptures)
captures := make([]string, 0, len(groups)/2)
for j := 0; j < len(groups); j += 2 {
captures = append(captures, content[groups[j]:groups[j+1]])