I am trying to use golang regexp to find the repetition of digits. Here is what I have tried to find repetitive digits of length 8. I was trying to follow the suggestion at Regex to find repeating numbers
testString := "11111111"
repetitive := `^(\d)\\1{8}$`
repetitiveR := regexp.MustCompile(repetitive)
if repetitiveR.MatchString(testString) {
fmt.Println("Match")
} else {
fmt.Println("No match")
}
It always gives me result as "No match". Another way that works it is cumbersome
testString := "11111111"
repetitive := `^(0{8})|(1{8})|(2{8})|(3{8})|(4{8})|(5{8})|(6{8})|(7{8})|(8{8})|(9{8})$`
repetitiveR := regexp.MustCompile(repetitive)
if repetitiveR.MatchString(testString) {
fmt.Println("Match")
} else {
fmt.Println("No match")
}
Output: Match
Any suggestions