Add some more shorthands for regex

This commit is contained in:
2025-03-26 12:06:04 +01:00
parent 6a3d44ccd0
commit b63b4d1352

View File

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