Add named capture group tests
This commit is contained in:
@@ -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]])
|
||||
|
Reference in New Issue
Block a user