From 93249969614a632e3e83f9cfa43777c149f3807c Mon Sep 17 00:00:00 2001 From: Ice3man543 Date: Thu, 17 Sep 2020 12:01:51 +0530 Subject: [PATCH] Added group capturing in backward compatible way --- pkg/extractors/extract.go | 8 +++++--- pkg/extractors/extractors.go | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/extractors/extract.go b/pkg/extractors/extract.go index 10a879404..f6e2df400 100644 --- a/pkg/extractors/extract.go +++ b/pkg/extractors/extract.go @@ -54,13 +54,15 @@ func (e *Extractor) ExtractDNS(msg *dns.Msg) map[string]struct{} { func (e *Extractor) extractRegex(corpus string) map[string]struct{} { results := make(map[string]struct{}) + groupPlusOne := e.RegexGroup + 1 for _, regex := range e.regexCompiled { - matches := regex.FindAllString(corpus, -1) + matches := regex.FindAllStringSubmatch(corpus, -1) for _, match := range matches { - results[match] = struct{}{} + if len(match) >= groupPlusOne { + results[match[e.RegexGroup]] = struct{}{} + } } } - return results } diff --git a/pkg/extractors/extractors.go b/pkg/extractors/extractors.go index ddfd07990..4f78d5042 100644 --- a/pkg/extractors/extractors.go +++ b/pkg/extractors/extractors.go @@ -13,6 +13,8 @@ type Extractor struct { // Regex are the regex pattern required to be present in the response Regex []string `yaml:"regex"` + // RegexGroup specifies a group to extract from the regex + RegexGroup int `yaml:"group"` // regexCompiled is the compiled variant regexCompiled []*regexp.Regexp @@ -25,7 +27,6 @@ type Extractor struct { Part string `yaml:"part,omitempty"` // part is the part of the request to match part Part - // Internal defines if this is used internally Internal bool `yaml:"internal,omitempty"` }