I want to check if a string contains repetitive patterns above a threshold .
For example, these two strings both exceed a threshold of 2:
"xyzxyzxyz" // contains "xyz" 3 times in succession
"abxyxyxyns" // contains "xy" 3 times in succession
Does anyone know how this is possible?
Use the "repetitions" modifier.
re := regexp.MustCompile(`(xy){3,}`) // match "xy" 3 or more times
fmt.Println(re.MatchString("abxyxyns")) // false
fmt.Println(re.MatchString("abxyxyxyns")) // true
The available options for the regpexp package's RE2 implementation are documented here: