Add some more shorthands for regex
This commit is contained in:
@@ -74,7 +74,21 @@ func (p *RegexProcessor) ProcessContent(content string, pattern string, luaExpr
|
|||||||
log.Printf("Pattern modified to include (?s): %s", pattern)
|
log.Printf("Pattern modified to include (?s): %s", pattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = strings.ReplaceAll(pattern, "!num", `(\d*\.?\d+)`)
|
pattern = strings.ReplaceAll(pattern, "!num", `"?(\d*\.?\d+)"?`)
|
||||||
|
pattern = strings.ReplaceAll(pattern, "!any", `.*?`)
|
||||||
|
repPattern := regexp.MustCompile(`!rep\(([^,]+),\s*(\d+)\)`)
|
||||||
|
// !rep(pattern, count) repeats the pattern n times
|
||||||
|
// Inserting !any between each repetition
|
||||||
|
pattern = repPattern.ReplaceAllStringFunc(pattern, func(match string) string {
|
||||||
|
parts := repPattern.FindStringSubmatch(match)
|
||||||
|
if len(parts) != 3 {
|
||||||
|
return match
|
||||||
|
}
|
||||||
|
repeatedPattern := parts[1]
|
||||||
|
count := parts[2]
|
||||||
|
repetitions, _ := strconv.Atoi(count)
|
||||||
|
return strings.Repeat(repeatedPattern+".*?", repetitions-1) + repeatedPattern
|
||||||
|
})
|
||||||
|
|
||||||
compiledPattern, err := regexp.Compile(pattern)
|
compiledPattern, err := regexp.Compile(pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user