Added group capturing in backward compatible way

This commit is contained in:
Ice3man543 2020-09-17 12:01:51 +05:30
parent 9f10341627
commit 9324996961
2 changed files with 7 additions and 4 deletions

View File

@ -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
}

View File

@ -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"`
}